[YANGTOOLS-1253] Optimize StatementContextBase layout Created: 17/Feb/21 Updated: 18/Feb/21 Resolved: 18/Feb/21 |
|
| Status: | Resolved |
| Project: | yangtools |
| Component/s: | parser |
| Affects Version/s: | None |
| Fix Version/s: | 7.0.0 |
| Type: | Improvement | Priority: | Medium |
| Reporter: | Robert Varga | Assignee: | Robert Varga |
| Resolution: | Done | Votes: | 0 |
| Labels: | pt | ||
| Σ Remaining Estimate: | Not Specified | Remaining Estimate: | Not Specified |
| Σ Time Spent: | Not Specified | Time Spent: | Not Specified |
| Σ Original Estimate: | Not Specified | Original Estimate: | Not Specified |
| Issue Links: |
|
|||||||||||||||
| Sub-Tasks: |
|
|||||||||||||||
| Epic Link: | Parser Performance | |||||||||||||||
| 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:
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. |