You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this code sample above in the html I call @Sloc two times, thus having two times a "get" call for the IStringLocalizer being made.
When we translate every label, tooltip, etc... there an be easily 50 to 100 '@Sloc-getters' in one view or component.
Is it recommended to cache e.g. the StringLocalizer so that we reduce the number of "get"s on the stringlocalizer each time we need a translation on this razor page and instead use a local variable?
(I've optimized code in the past and have seen slow code paths when rendering (image conversion etc...) where we had to cache the getter so that it was only accessed once to gain a lot of performance. because the compiler didn't optimize it)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I will use IStringLocalizer as a sample but it is a general question for
@inject
'ed objects.When using
@inject
in a .razor page the injected item is available as an auto-property (accessed via a getter/setter).For example:
In this code sample above in the html I call
@Sloc
two times, thus having two times a "get" call for the IStringLocalizer being made.When we translate every label, tooltip, etc... there an be easily 50 to 100 '
@Sloc
-getters' in one view or component.Another example where we have 3 'gets' :
<img src="images/foo.png" class="mr-1" title="@Sloc["abc"]" alt="@Sloc["abc"]" /><span class="badge badge-secondary">@Sloc["abc"]</span>
Is it recommended to cache e.g. the StringLocalizer so that we reduce the number of "get"s on the stringlocalizer each time we need a translation on this razor page and instead use a local variable?
(I've optimized code in the past and have seen slow code paths when rendering (image conversion etc...) where we had to cache the getter so that it was only accessed once to gain a lot of performance. because the compiler didn't optimize it)
Beta Was this translation helpful? Give feedback.
All reactions