Bug 295171
| Summary: | Padding bits defeat intended HTMLEntityTableEntry size optimization | ||
|---|---|---|---|
| Product: | WebKit | Reporter: | squeek502 |
| Component: | DOM | Assignee: | Darin Adler <darin> |
| Status: | ASSIGNED | ||
| Severity: | Normal | CC: | cdumez, darin, nathan_solomon, rreno, webkit-bug-importer |
| Priority: | P2 | Keywords: | InRadar |
| Version: | WebKit Nightly Build | ||
| Hardware: | Unspecified | ||
| OS: | Unspecified | ||
squeek502
In https://github.com/WebKit/WebKit/pull/11089, HTMLEntityTableEntry was converted to a bit-field in order to decrease the size of kStaticEntityTable. HTMLEntityTableEntry theoretically uses 57 bits, but, due to padding bits, the size of HTMLEntityTableEntry is actually 12 bytes instead of 8 bytes (the same size it was before the bit-field change).
Test code:
struct HTMLEntityTableEntry {
unsigned firstCharacter : 21;
unsigned optionalSecondCharacter : 16;
unsigned nameCharactersOffset : 14;
unsigned nameLengthExcludingSemicolon : 5;
unsigned nameIncludesTrailingSemicolon : 1;
};
static_assert(sizeof(HTMLEntityTableEntry) == 8);
Clang 20.1.3:
HTMLEntityTableEntry.cpp:8:15: error: static assertion failed due to requirement 'sizeof(HTMLEntityTableEntry) == 8'
8 | static_assert(sizeof(HTMLEntityTableEntry) == 8);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HTMLEntityTableEntry.cpp:8:44: note: expression evaluates to '12 == 8'
8 | static_assert(sizeof(HTMLEntityTableEntry) == 8);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
1 error generated.
GCC 11.4.0:
HTMLEntityTableEntry.cpp:8:44: error: static assertion failed
8 | static_assert(sizeof(HTMLEntityTableEntry) == 8);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
(for context, this was found while I was writing https://www.ryanliptak.com/blog/better-named-character-reference-tokenization/)
| Attachments | ||
|---|---|---|
| Add attachment proposed patch, testcase, etc. |
Darin Adler
I tried moving optionalSecondCharacter to be the last member of the HTMLEntityTableEntry structure and that worked; just have to revise the code that builds the table to write out the members in the right order.
Radar WebKit Bug Importer
<rdar://problem/155138028>