Uploaded image for project: 'yangtools'
  1. yangtools
  2. YANGTOOLS-1253

Optimize StatementContextBase layout

    XMLWordPrintable

Details

    • Improvement
    • Status: Resolved
    • Medium
    • Resolution: Done
    • None
    • 7.0.0
    • parser

    Description

      We currently store CopyHistory as a reference to an object, costing us 4b/8b of storage in StatementContextBase.

      StatementContextBase is the bread&butter of memory/CPU trade-offs and it does not have a single bit of storage left.

      At the end of the day, CopyHistory encodes the following information:

      • last CopyType
      • CopyableNode.isAugmenting()
      • AddedByUsesAware.isAddedByUses()

      This currently boils down to 2+log2(4)=4 significant bits, for which we are storing 32/64 bits.

      Refactor StatementContextBase.copyHistory to be

      private final byte copyHistory;
      

      This frees up 3-7 bytes of storage, which provides 24bits of additional free storage.

       

      Another candidate is StatementContextBase.completedPhase, which again is 4/8 bytes of storage, but it only stores 7 states, i.e. none + ModelProcessingPhase which there are 6 of.

      We could use only 3 bits for storing that state, but that would incur masking operations for sub-byte access. Since this is an utterly hot path, let's instead keep

      private byte completedPhase;

      Which again frees up 3-7 bytes of storage.

       

      Combining these two, though, we get real gains – we trim down 8-16 bytes of storage for everything 64bit, while also a creating an unused 2-byte alignment gap. There also remain 4 unused bits in copyHistory, giving us comfortable 20bits if we need to store more information.

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              rovarga Robert Varga
              rovarga Robert Varga
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: