ThreeTen / threeten

This project was the home of code used to develop a modern date and time library for JDK8. Development has moved to OpenJDK and a separate backport project, threetenbp.
http://threeten.github.io/
191 stars 37 forks source link

Performance of Localized calendar initializations and Chronology.getAvailableChronologies() #263

Closed RogerRiggs closed 11 years ago

RogerRiggs commented 11 years ago

The initial set of localized calendars had relatively light initializations, just creating the Chronology instance. As the Japanese and Hijrah Chronologies has been refined the amount of work needed to initialize the Chronology has increased. Reading the data for the Umm alQura calendar adds 30+ms to the initialization time.

Currently, the Chronology of, ofLocale, getAvailableChronologies all initialize all of the Chronologies to be able to return the complete set of Chronologies.

It would be better to initialize each Chronology only when it will be used by the application. Two approaches are possible:

  1. Change getAvailableChronologies to return the String ids of the chronologies and change the of method to initialize only the Chronology requested.
  2. Change each of the heavyweight chronologies to create the Chronology instance as a quickly as possible and delay the reading of the data until it was needed. This may be more complex either by adding state within the Chronology or delegating to a separate class for the data.
  3. Initially register a simple proxy for the Chronology that would initialize the data on first use and then replace itself in the list of registered Chronologies.
jodastephen commented 11 years ago

I don't think I overly care, although I'm naturally drawn to option 2. I think there may be an argument for changing getAvailableChronologies to return String anyway, as per ZoneId

RogerRiggs commented 11 years ago

Resolved by http://hg.openjdk.java.net/threeten/threeten/jdk/rev/bfd5f5ef2281