JDK-8231057 : Optimize search algorithm for determining default time zone
  • Type: CSR
  • Component: core-libs
  • Sub-Component: java.util
  • Priority: P3
  • Status: Closed
  • Resolution: Approved
  • Fix Versions: 7u251,8u241,11.0.6-oracle,14
  • Submitted: 2019-09-16
  • Updated: 2019-09-16
  • Resolved: 2019-09-16
Related Reports
CSR :  
Description
Summary
-------
The current algorithm for determining the default timezone on (non-AIX) is sub-optimal if the /etc/localtime file needs to be matched with an identical timezone file from the OS zoneinfo directory. 

Planning to make an enhancement in this area which could be ported to JDK 14, 11.x, 8ux-oracle and 7ux.

Problem
-------

The current algorithm for determining the default timezone on (non-AIX) unix systems goes something like :

1. If *TZ* environment variable is defined, use it
2. else if */etc/timezone* exists, use the value contained within it
3. else if */etc/localtime* exists and is a symbolic link, use the name pointed to
4. else if */etc/localtime* is a binary file, find the **first** identical time zone binary file in */usr/share/zoneinfo/* (*/usr/share/lib/zoneinfo* on solaris)

Step 4 is a bit crude in that the *zoneinfo* directory can contain over 1,800 files on today's systems. I'd like to change the logic so that common timezones are first checked for buffer matching before a full directory traversal is performed. It should be a performance gain and it should also lead to more consistent results for reasons outlined in the solution section.

Solution
--------

The solution involves specifying a handful of common, popular time zones that are first tested for a match before iterating through the *zoneinfo* contents.

If the */etc/localtime* data file matches one of the common time zones, then the matching time zone is returned immediately without having to perform a directory traversal on *zoneinfo*

There's an obvious performance benefit here. The change also means that the name of the default timezone is not subject to how the OS may traverse files within the directory. In the current implementation, any of ("UTC", "UCT", "Universal", "Zulu") could be returned by the JDK as the default time zone for an OS which has */etc/localtime* matching the UTC time zone. Returning the common well known name is best behaviour here.

Specification
-------------

The time zone algorithm will remained unchanged for steps 1, 2 and 3 described above. For step 4, the "GMT" and "UTC" time zones will have a fast path where they'll be tested for a matching data file before traversing through the *zoneinfo* file contents.


Comments
Moving to Approved.
16-09-2019