JDK-6307385 : Locale performance and correctness fixes
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.util:i18n
  • Affected Version: 6
  • Priority: P4
  • Status: Resolved
  • Resolution: Won't Fix
  • OS: generic
  • CPU: generic
  • Submitted: 2005-08-06
  • Updated: 2015-10-16
  • Resolved: 2015-10-16
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Description
A DESCRIPTION OF THE FIX :
A collection of Locale fixes.

LocaleData.scanFile reads through the length of zip files on the classpath using ZipINputStream. I have replaced that with ZipFile that zips straight to the index. On my machine that improves the performance of the first call of Locale.getAvailableLocales by around *seven seconds*. I'm sure it could be done better still as we will have loaded classes through these zips. But this is the low hanging fruit.

LocaleServiceProvider.allAvailableLocales and  LocaleData.localeList are initialised with double-checked locking. I have replaced that with nested class initialisation.

The key used for the Locale cache is not unique for all possible arguments. In some cases it can fail to NPE, although I don't believe this is possible through the current usage within the package. The useful language constants also have bizarre duplication in their initialisation. I've replace the String key with a three element Arrays.asList.

Changed Locale.hashCode from lazy to eager initialisation. There is no great in deferring the initialisation. Doing it lazily complicates the hashCode method, requires another field and always recomputes for Locale("", "", "").

The LocaleISOData splits a String of country and ISO names. This means that the strings used are not interned (although the initialisation code is shorter). Strings used in actual locales are always interned. I've replaced it with more conventional initialisation to keep the strings interned as the class loads on demand rather than allocated twice later. The real overheads are in the locale property files.

Diffs against 1.6.0 ea b45.

(Diffs are too large to include here.  Refer to the attached
 file '504032-diffs.txt')

Comments
LocaleData loading mechanism has vastly changed from the days this bug was filed, so the suggested performance improvement won't be directly applied. We are tracking loading locale data with other bug ids (cf. links)
16-10-2015

EVALUATION Contribution-Forum:https://jdk-collaboration.dev.java.net/servlets/ProjectForumMessageView?messageID=12042&forumID=1463
16-03-2006

EVALUATION Remaining stuff are now targeted for Dolphin.
27-02-2006

EVALUATION The double check locking issue and the Locale.getInstance failing to NPE are separately addressed in 6312351 and 6312358 respectively. Other remaining issues (cache key as a list, hashCode, and intern'ing LocaleISOData strings) are all related to performance, and this bug report remains open to address those issues, which requires detailed performance analysis.
17-08-2005

EVALUATION The first issue will be addressed by the fix for bug 4908648, which pre-calculates the available locale list at build time.
15-08-2005