Fold _canHavePrefixUri into Xobj._bits to shrink AttrXobj by 8 bytes - #115
Merged
Merged
Conversation
NamedNodeXobj carries a single boolean, _canHavePrefixUri, to record whether a node was created through the DOM Level 1 factory methods. Xobj already ends on an 8-byte boundary, so that one byte costs AttrXobj a whole 8-byte slot: 88 bytes of fields become a 96-byte object with 7 bytes of padding. Xobj._bits already holds kind, domType and three flags, with the highest bit in use at 0x400. Moving the boolean there as CAN_HAVE_PREFIX_URI = 0x800 removes the field, and AttrXobj drops to 88 bytes. Measured with Unsafe.objectFieldOffset on JDK 17 and 21, with and without compressed oops. ElementXobj is unchanged at 96 - it adds a 4-byte _attributes reference on top of 88. Reported against POI as a 600MB workbook holding 2.35 million AttrXobj, where this is roughly 19MB. Refs apache/poi#992 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs apache/poi#992, where a 600MB workbook was reported to hold 2.35 million
AttrXobj(216MB) and 1.17 millionElementXobj(108MB).NamedNodeXobjcarries one boolean,_canHavePrefixUri, recording whether a node came from the DOM Level 1 factory methods (createElement/createAttribute), which must reportnullforlocalName,namespaceURIandprefix.Xobjalready ends exactly on an 8-byte boundary at 88 bytes, so that single byte costsAttrXobja whole slot — 89 bytes of fields padded out to a 96-byte object.Xobj._bitsalready packskind(0xF),domType(0xF0) and three flags, the highest beingINHIBIT_DISCONNECT = 0x400. Moving the boolean there asCAN_HAVE_PREFIX_URI = 0x800removes the field entirely.Measured with
Unsafe.objectFieldOffseton the compiled classes, JDK 17 and JDK 21:XobjAttrXobjElementXobjThe saving also holds with
-XX:-UseCompressedOops(152 → 144). For the reported workload that is roughly 19MB, about 3%.ElementXobjstays at 96 because it adds a 4-byte_attributesreference on top of 88; nothing in this change can help there.Relation to the patch proposed on the issue
The issue proposes narrowing
_bitsfrominttoshort, which produces exactly the same layout — I measured both, and combining them gains nothing further. This approach reaches the same result without changing the type, so there is no compound-assignment narrowing or sign-extension behaviour to reason about and no need for the range assertions that patch adds;_bitskeeps all 32 bits available for future flags. Either is correct; this one is the smaller change to reason about.Behaviour
Identical. The bit is set in the
NamedNodeXobjconstructor, cleared at the two DOM Level 1 factory sites, and set again on rename inXobj.setName— the same three writes as before, andNamedNodeXobjremains the only reader. No otherXobjsets0x800.Added
NodePrefixUriFlagTest, covering all three write paths. It passes on trunk as well — it is a characterisation test for the invariant this refactor must preserve, not a bug fix.Full suite: 3182 tests pass (170 skipped), including the W3C DOM conformance suite.
forbiddenApisMainpasses.🤖 Generated with Claude Code