default resource file without culture information is performance hit?

  • Thread starter Thread starter TS
  • Start date Start date
T

TS

I'm wondering if i get a performance hit in this scenario: I believe that
the .net engine will first look for resource file matching current user's
culture and if it doesnt find it then it will go to the default resource
file (simply resourceName.resx).

If in my application i dont create a resource file for en-US and just make
it so the values in the default resource file contains the en-US values, for
these clients (99% of the time) the engine will not find an en-US so it will
use the default resource file - so is this extra check going to affect
performance at all?

thanks!
 
Hello TS,

After analyzing your scenario, looking into the source code of
ResourceManager and testing with fuslogvw.exe, I suggest your having this
attribute in the main assembly:

[assembly: NeutralResourcesLanguageAttribute("en-US")]
http://msdn.microsoft.com/en-us/library/hhz003sc.aspx

And I believe this may optimize the performance in the following aspect:

=====================================
I looked into the source code of ResourceManager
(http://blogs.msdn.com/sburke/archiv...tudio-to-debug-net-framework-source-code.aspx).
The functions to locate the satellite assembly is: InternalGetResourceSet,
which has this piece of code:

if (UseSatelliteAssem) {
CultureInfo lookForCulture = culture;
if (_neutralResourcesCulture == null)
_neutralResourcesCulture = GetNeutralResourcesLanguage(MainAssembly,
ref _fallbackLoc);
// If our neutral resources were written in this culture
// AND we know the main assembly does NOT contain neutral
// resources, don't probe for this satellite.
if (culture.Equals(_neutralResourcesCulture) &&
FallbackLocation == UltimateResourceFallbackLocation.MainAssembly)
{
// Update internal state.
lookForCulture = CultureInfo.InvariantCulture;
fileName = GetResourceFileName(lookForCulture);
}
// For neutral locale, look in the main assembly
// if and only if our fallback location is MainAssembly.
if (lookForCulture.Equals(CultureInfo.InvariantCulture)) {
......
}
else
satellite = GetSatelliteAssembly(lookForCulture);
}

The function GetNeutralResourcesLanguage returns our setting in
NeutralResourcesLanguageAttribute and compares it with CurrentUICulture. If
it equals, InternalGetResourceSet retrieves the default resource file by
looking in the main assembly.

Because in 99% cases, our client's culture is en-US. The setting of
NeutralResourcesLanguageAttribute ensures that the assembly will not look
other places for the satellite assemblies in most situations. Please also
note that GetNeutralResourcesLanguage returns CultureInfo.InvariantCulture
when we do not have NeutralResourcesLanguageAttribute. In other words,
InternalGetResourceSet will not benefit from this optimization when
NeutralResourcesLanguageAttribute is not declared.

As a test, I used fuslogvw
(http://msdn.microsoft.com/en-us/library/e74a18c4(VS.71).aspx) to observe
the binding behavior of the satellite assemblies. When I set
NeutralResourcesLanguageAttribute, I see my app (CurrentUICulture = en-US)
only look for the natural resources and all the accesses are successful.

Please let me know whether the above suggestion is helpful to you. If you
have any other questions or concerns, DON'T hesitate to tell me.

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/default.aspx?target=assistance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hello TS,

I forgot to emphasize one point in my last reply:

Please make sure that ALL your assemblies using resource assemblies have
the NeutralResourcesLanguageAttribute in AssemblyInfo.cs

[assembly: NeutralResourcesLanguageAttribute("en-US")]

If one assembly that uses the resource assembly does not have this
attribute, this assembly won't benefit from the optimization. In other
words, this assembly will still look for the resource dll in GAC and the
current/parent directory and fail to find it.

Regards,
Jialiang Ge
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================
 
Hello TS,

I am writing to check the status of the issue on your side. Would you mind
letting me know the result of the suggestions? If you need further
assistance, feel free to let me know. I will be more than happy to be of
assistance.

Have a great day!

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================
 
so you are saying that with this assembly attribute, i can just have the
default resource file sample.resx and don't need sample.en-US.resx and
there'll be no performance hit?

thanks!

Jialiang Ge said:
Hello TS,

After analyzing your scenario, looking into the source code of
ResourceManager and testing with fuslogvw.exe, I suggest your having this
attribute in the main assembly:

[assembly: NeutralResourcesLanguageAttribute("en-US")]
http://msdn.microsoft.com/en-us/library/hhz003sc.aspx

And I believe this may optimize the performance in the following aspect:

=====================================
I looked into the source code of ResourceManager
(http://blogs.msdn.com/sburke/archiv...tudio-to-debug-net-framework-source-code.aspx).
The functions to locate the satellite assembly is: InternalGetResourceSet,
which has this piece of code:

if (UseSatelliteAssem) {
CultureInfo lookForCulture = culture;
if (_neutralResourcesCulture == null)
_neutralResourcesCulture = GetNeutralResourcesLanguage(MainAssembly,
ref _fallbackLoc);
// If our neutral resources were written in this culture
// AND we know the main assembly does NOT contain neutral
// resources, don't probe for this satellite.
if (culture.Equals(_neutralResourcesCulture) &&
FallbackLocation ==
UltimateResourceFallbackLocation.MainAssembly) {
// Update internal state.
lookForCulture = CultureInfo.InvariantCulture;
fileName = GetResourceFileName(lookForCulture);
}
// For neutral locale, look in the main assembly
// if and only if our fallback location is MainAssembly.
if (lookForCulture.Equals(CultureInfo.InvariantCulture)) {
......
}
else
satellite = GetSatelliteAssembly(lookForCulture);
}

The function GetNeutralResourcesLanguage returns our setting in
NeutralResourcesLanguageAttribute and compares it with CurrentUICulture.
If it equals, InternalGetResourceSet retrieves the default resource file
by looking in the main assembly.

Because in 99% cases, our client's culture is en-US. The setting of
NeutralResourcesLanguageAttribute ensures that the assembly will not look
other places for the satellite assemblies in most situations. Please also
note that GetNeutralResourcesLanguage returns CultureInfo.InvariantCulture
when we do not have NeutralResourcesLanguageAttribute. In other words,
InternalGetResourceSet will not benefit from this optimization when
NeutralResourcesLanguageAttribute is not declared.

As a test, I used fuslogvw
(http://msdn.microsoft.com/en-us/library/e74a18c4(VS.71).aspx) to observe
the binding behavior of the satellite assemblies. When I set
NeutralResourcesLanguageAttribute, I see my app (CurrentUICulture = en-US)
only look for the natural resources and all the accesses are successful.

Please let me know whether the above suggestion is helpful to you. If you
have any other questions or concerns, DON'T hesitate to tell me.

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/default.aspx?target=assistance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.

TS said:
I'm wondering if i get a performance hit in this scenario: I believe that
the .net engine will first look for resource file matching current user's
culture and if it doesnt find it then it will go to the default resource
file (simply resourceName.resx).

If in my application i dont create a resource file for en-US and just
make it so the values in the default resource file contains the en-US
values, for these clients (99% of the time) the engine will not find an
en-US so it will use the default resource file - so is this extra check
going to affect performance at all?

thanks!
 
Yes, you understand it rightly. And to some extent, I think that it will
even improve the performance a little bit. (the reason was explained in my
initial reply)

Let me know whenever you have questions/concerns!

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================
 
so you're saying that if i have an assembly that calls a method in another
assembly which accesses resource information, both assemblies need the
reference?
 
Hello TS,

No. Only the assembly that access resource information needs this attribute.
For example, assembly A references assembly B. A does not use resource
files but B does, we only need to add the NeutralResourcesLanguageAttribute
attribute in B.

Have a nice day!

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================

TS said:
so you're saying that if i have an assembly that calls a method in another
assembly which accesses resource information, both assemblies need the
reference?


"Jialiang Ge [MSFT]" said:
Hello TS,

I forgot to emphasize one point in my last reply:

Please make sure that ALL your assemblies using resource assemblies have
the NeutralResourcesLanguageAttribute in AssemblyInfo.cs

[assembly: NeutralResourcesLanguageAttribute("en-US")]

If one assembly that uses the resource assembly does not have this
attribute, this assembly won't benefit from the optimization. In other
words, this assembly will still look for the resource dll in GAC and the
current/parent directory and fail to find it.

Regards,
Jialiang Ge
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you.
Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no
rights.
=================================================
 
Back
Top