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

ZoneIdPrinterParser can be optimized #350

Closed Aubineau closed 9 years ago

Aubineau commented 10 years ago

Every time you parse a ZonedDateTime that contains a zone id the method ZoneRulesProvider.getAvailableZoneIds() is called in the ZoneIdPrinterParser.

This method can be very costly. Since there is already a cache to avoid to recreate the SubstringTree it should be possible to call the ZoneRulesProvider.getAvailableZoneIds() method only when this cache is updated.

For example something like

Set regionIds = cachedRegionIds; final int regionIdsSize = ZoneRulesProvider.getAvailableZoneIdsSize(); // Return only the size of ZONES in ZoneRulesProvider Entry<Integer, SubstringTree> cached = cachedSubstringTree; if (cached == null || cached.getKey() != regionIdsSize) { cachedRegionIds = ZoneRulesProvider.getAvailableZoneIds(); ...

Instead of

Set regionIds = ZoneRulesProvider.getAvailableZoneIds(); final int regionIdsSize = regionIds.size(); Entry<Integer, SubstringTree> cached = cachedSubstringTree; if (cached == null || cached.getKey() != regionIdsSize) { ...

Eric

cowwoc commented 9 years ago

@Aubineau I don't think this project is being actively maintained.

Consider closing this issue and re-posting it at https://github.com/ThreeTen/threeten-extra

RogerRiggs commented 9 years ago

Created OpenJDK matching issue: https://bugs.openjdk.java.net/browse/JDK-8066291