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 :
- If TZ environment variable is defined, use it
- else if /etc/timezone exists, use the value contained within it
- else if /etc/localtime exists and is a symbolic link, use the name pointed to
- 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.
- csr of
-
JDK-8223490 Optimize search algorithm for determining default time zone
-
- Closed
-