You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "Thomas Mueller (JIRA)" <ji...@apache.org> on 2009/03/03 10:24:56 UTC
[jira] Created: (SLING-877) Avoid calling
Locale.getAvailableLocales() because it is very slow
Avoid calling Locale.getAvailableLocales() because it is very slow
------------------------------------------------------------------
Key: SLING-877
URL: https://issues.apache.org/jira/browse/SLING-877
Project: Sling
Issue Type: Improvement
Components: Extensions
Reporter: Thomas Mueller
Currently, JcrResourceBundleProvider.toLocale calls Locale.getAvailableLocales().
The first call to this method is very slow (3.4 seconds on my machine) because
it scans many jar files.
http://svn.apache.org/viewvc/incubator/sling/trunk/bundles/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundleProvider.java?view=markup
It looks like calling this method is not required.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (SLING-877) Avoid calling
Locale.getAvailableLocales() because it is very slow
Posted by "Alexander Klimetschek (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/SLING-877?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12678689#action_12678689 ]
Alexander Klimetschek commented on SLING-877:
---------------------------------------------
toLocale() is only called during the component activation to set the default
locale based on the component configuration. I can imagine two optimizations:
a) make this lazy-loading (not sure when this might be called):
private Locale internalGetDefaultLocale() {
if (this.defaultLocale == null) {
this.defaultLocale = toLocale(localeString);
}
}
b) since in most cases the default locale will be english anyway, a simple
check could skip toLocale() and the performance intensive
Locale.getAvailableLocales() completely:
if ("en".equals(localeString)) {
this.defaultLocale = Locale.ENGLISH;
} else {
this.defaultLocale = internalGetDefaultLocale();
}
> Avoid calling Locale.getAvailableLocales() because it is very slow
> ------------------------------------------------------------------
>
> Key: SLING-877
> URL: https://issues.apache.org/jira/browse/SLING-877
> Project: Sling
> Issue Type: Improvement
> Components: Extensions
> Reporter: Thomas Mueller
>
> Currently, JcrResourceBundleProvider.toLocale calls Locale.getAvailableLocales().
> The first call to this method is very slow (3.4 seconds on my machine) because
> it scans many jar files.
> http://svn.apache.org/viewvc/incubator/sling/trunk/bundles/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundleProvider.java?view=markup
> It looks like calling this method is not required.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Resolved: (SLING-877) Avoid calling
Locale.getAvailableLocales() because it is very slow
Posted by "Felix Meschberger (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/SLING-877?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Felix Meschberger resolved SLING-877.
-------------------------------------
Resolution: Fixed
Fix Version/s: Extensions i18n 2.0.2
Thanks for providing the patch. I have applied it in Rev. 751682
Please close this issue, if this is ok for you. Thanks.
> Avoid calling Locale.getAvailableLocales() because it is very slow
> ------------------------------------------------------------------
>
> Key: SLING-877
> URL: https://issues.apache.org/jira/browse/SLING-877
> Project: Sling
> Issue Type: Improvement
> Components: Extensions
> Reporter: Thomas Mueller
> Assignee: Felix Meschberger
> Fix For: Extensions i18n 2.0.2
>
> Attachments: JcrResourceBundleProvider.patch
>
>
> Currently, JcrResourceBundleProvider.toLocale calls Locale.getAvailableLocales().
> The first call to this method is very slow (3.4 seconds on my machine) because
> it scans many jar files.
> http://svn.apache.org/viewvc/incubator/sling/trunk/bundles/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundleProvider.java?view=markup
> It looks like calling this method is not required.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (SLING-877) Avoid calling
Locale.getAvailableLocales() because it is very slow
Posted by "Bertrand Delacretaz (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/SLING-877?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12678718#action_12678718 ]
Bertrand Delacretaz commented on SLING-877:
-------------------------------------------
Agree with Jukka that not doing any checks seems reasonable.
Do you know what's specified to happen if calling new Locale("foo", "bar") and there's no foo_bar locale available?
In a quick test I seem to get the VM's default locale in that case, but the Locale javadocs don't specify this case.
> Avoid calling Locale.getAvailableLocales() because it is very slow
> ------------------------------------------------------------------
>
> Key: SLING-877
> URL: https://issues.apache.org/jira/browse/SLING-877
> Project: Sling
> Issue Type: Improvement
> Components: Extensions
> Reporter: Thomas Mueller
> Attachments: JcrResourceBundleProvider.patch
>
>
> Currently, JcrResourceBundleProvider.toLocale calls Locale.getAvailableLocales().
> The first call to this method is very slow (3.4 seconds on my machine) because
> it scans many jar files.
> http://svn.apache.org/viewvc/incubator/sling/trunk/bundles/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundleProvider.java?view=markup
> It looks like calling this method is not required.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Assigned: (SLING-877) Avoid calling
Locale.getAvailableLocales() because it is very slow
Posted by "Felix Meschberger (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/SLING-877?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Felix Meschberger reassigned SLING-877:
---------------------------------------
Assignee: Felix Meschberger
> Avoid calling Locale.getAvailableLocales() because it is very slow
> ------------------------------------------------------------------
>
> Key: SLING-877
> URL: https://issues.apache.org/jira/browse/SLING-877
> Project: Sling
> Issue Type: Improvement
> Components: Extensions
> Reporter: Thomas Mueller
> Assignee: Felix Meschberger
> Attachments: JcrResourceBundleProvider.patch
>
>
> Currently, JcrResourceBundleProvider.toLocale calls Locale.getAvailableLocales().
> The first call to this method is very slow (3.4 seconds on my machine) because
> it scans many jar files.
> http://svn.apache.org/viewvc/incubator/sling/trunk/bundles/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundleProvider.java?view=markup
> It looks like calling this method is not required.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (SLING-877) Avoid calling
Locale.getAvailableLocales() because it is very slow
Posted by "Felix Meschberger (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/SLING-877?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12680148#action_12680148 ]
Felix Meschberger commented on SLING-877:
-----------------------------------------
@Bertrand
The ResourceBundle class java doc specifies what is been done in this case. Bascially it checks for foo_bar, then foo and then default locale resources.
@Jukka
I suggest we keep the language and country checks, because these verify, the language and country codes are really valid according to ISO 3166.
> Avoid calling Locale.getAvailableLocales() because it is very slow
> ------------------------------------------------------------------
>
> Key: SLING-877
> URL: https://issues.apache.org/jira/browse/SLING-877
> Project: Sling
> Issue Type: Improvement
> Components: Extensions
> Reporter: Thomas Mueller
> Attachments: JcrResourceBundleProvider.patch
>
>
> Currently, JcrResourceBundleProvider.toLocale calls Locale.getAvailableLocales().
> The first call to this method is very slow (3.4 seconds on my machine) because
> it scans many jar files.
> http://svn.apache.org/viewvc/incubator/sling/trunk/bundles/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundleProvider.java?view=markup
> It looks like calling this method is not required.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (SLING-877) Avoid calling
Locale.getAvailableLocales() because it is very slow
Posted by "Thomas Mueller (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/SLING-877?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Thomas Mueller updated SLING-877:
---------------------------------
Attachment: JcrResourceBundleProvider.patch
This patch reduces the startup time for my application from 12 seconds to 9 seconds.
It does not seem to have any side-effect.
> Avoid calling Locale.getAvailableLocales() because it is very slow
> ------------------------------------------------------------------
>
> Key: SLING-877
> URL: https://issues.apache.org/jira/browse/SLING-877
> Project: Sling
> Issue Type: Improvement
> Components: Extensions
> Reporter: Thomas Mueller
> Attachments: JcrResourceBundleProvider.patch
>
>
> Currently, JcrResourceBundleProvider.toLocale calls Locale.getAvailableLocales().
> The first call to this method is very slow (3.4 seconds on my machine) because
> it scans many jar files.
> http://svn.apache.org/viewvc/incubator/sling/trunk/bundles/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundleProvider.java?view=markup
> It looks like calling this method is not required.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (SLING-877) Avoid calling
Locale.getAvailableLocales() because it is very slow
Posted by "Jukka Zitting (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/SLING-877?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12678709#action_12678709 ]
Jukka Zitting commented on SLING-877:
-------------------------------------
I would even question the need for the Locale.getISOLanguages() and Locale.getISOCountries() calls in the method. A Locale instance is just an identifier of the desired locale, so I'd argue that we should use the user-specified value as-is without trying to filter or map it according to what values the system may know about.
The method could well be something as simple as this:
String[] parts = localeString.split("_");
switch (parts.length) {
case 0: // empty locale string, use the default
return Locale.getDefault();
case 1: // only language
return new Locale(parts[0]);
case 2: // country is also available
return new Locale(parts[0], parts[1]);
case 3: // language, country and variant
default: // ... and skip everything after that
return new Locale(parts[0], parts[1], parts[2]);
}
> Avoid calling Locale.getAvailableLocales() because it is very slow
> ------------------------------------------------------------------
>
> Key: SLING-877
> URL: https://issues.apache.org/jira/browse/SLING-877
> Project: Sling
> Issue Type: Improvement
> Components: Extensions
> Reporter: Thomas Mueller
> Attachments: JcrResourceBundleProvider.patch
>
>
> Currently, JcrResourceBundleProvider.toLocale calls Locale.getAvailableLocales().
> The first call to this method is very slow (3.4 seconds on my machine) because
> it scans many jar files.
> http://svn.apache.org/viewvc/incubator/sling/trunk/bundles/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundleProvider.java?view=markup
> It looks like calling this method is not required.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.