Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8231057

Optimize search algorithm for determining default time zone


    • Subcomponent:
    • Compatibility Kind:
    • Compatibility Risk:
    • Interface Kind:
    • Scope:



      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.


      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.


      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.


      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.


          Issue Links



              • Assignee:
                coffeys Sean Coffey
                shadowbug Shadow Bug
                Reviewed By:
                Naoto Sato, Roger Riggs
              • Votes:
                0 Vote for this issue
                1 Start watching this issue


                • Created: