Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-170628

UserCache with X user entries writes the same file X times to disk on server startup

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • 20w27a
    • 1.15.2
    • None
    • Irrelevant for the cause, but the extra startup time is larger on slower drives (HDDs) than on faster drives (SSDs).
    • Community Consensus
    • Dedicated Server

      On server startup, user cache entries are read from the `usercache.json` file and added to the GameProfileCache object through a method that also stores the entire user cache. This causes a user cache of size 1000 (max size) to be read once and written 1000 times on server startup, creating a significant delay (tested 18 seconds) when running from a HDD.

       

      Code analysis:
      The GameProfileCache constructor calls GameProfileCache.load(), which reads all user cache entries and calls GameProfileCache.getProfileInfo(UUID) for each of them.
      The GameProfileCache.getProfileInfo(UUID) method makes a call to GameProfileCache.save(), which stores all user cache entries to the file.

       

      Proposed solutions:

      1.
          Set a boolean field to true when entering the loop in the `load()` method.
          Set this field to false when exiting this loop and call the `save()` method to save all changes at once.
          Do not perform saves when this boolean field is true.

      2.
          Add a boolean `saveToDisk` parameter to the `getProfileInfo(UUID)` method to save or don't save the file to disk at the end of this method.

            Unassigned Unassigned
            Pieter12345 pieter12345
            Votes:
            4 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:
              CHK: