Skip to content

Use constant metadata tables and per-model string pools - #265

Merged
danoli3 merged 3 commits into
danoli3:masterfrom
andre-rosa:metadata-constant-string-pools
Nov 9, 2026
Merged

danoli3 merged 3 commits into
danoli3:masterfrom
andre-rosa:metadata-constant-string-pools

Conversation

@andre-rosa

Copy link
Copy Markdown
Contributor

TagLib currently builds heap-allocated maps for fixed metadata tables. This series makes those tables constant, replaces string pointers with 16-bit pool offsets, and shares the lookup when a caller needs both a tag name and description.

The three commits are separated for review:

  1. Replace the maps with sorted constant tables and binary search. Preserve the lowest-ID result for duplicate names, empty Apple iOS model, returned string lifetimes, and unknown-tag fallbacks.
  2. Store strings in a separate pool for each model, so unused models can be discarded together. sizeof/offsetof compute the layout in C++98; a compile-time bound checks each pool. Rows remain editable in TagLibData.h, with no generator, runtime initialization, heap allocation, or mutable cache. Preserve the existing table attribution and this fork's copyright notice.
  3. Add internal getTagFields for the ten callers requesting both strings. Keep the original three-argument getTagFieldName symbol and getTagDescription. The public FreeImage C API is unchanged. Sharing the search reduces duplicate work; the pool representation still adds offset decoding, so this is not a claim that every individual lookup gets faster.

This is a port of SourceForge patch #199 and its two follow-ups. This fork's newer parser fixes and existing line endings are preserved. The standalone metadata regression is registered with CTest when BUILD_TESTS=ON, with assertions enabled in Release builds; legacy Makefile dependencies include the new header as well.

Validation on Linux:

  • GCC C++98 metadata regression passes after each commit: 1,572,864 model/tag lookups, plus sorted IDs, source/decoded strings, offset bounds, reverse names, stable pointers, and fallback behavior.
  • The final regression passes strict Clang ASan/UBSan and LeakSanitizer.
  • The full Release CMake/Ninja build passes, including bundled OpenEXR; all 18 CTest tests pass.
  • The pool rows, lookup implementation, and final regression match the separately validated SourceForge series, apart from this fork's existing unknown-model switch handling.

Build and test commands:

cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTS=ON -DFREEIMAGE_STATIC=ON
cmake --build build --parallel 8
ctest --test-dir build --output-on-failure
make -C TestAPI/Metadata check

Store metadata descriptors in sorted constant arrays instead of constructing
per-model maps at initialization. Binary search handles tag IDs; reverse name
lookup preserves the existing lowest-ID result for duplicate names. Descriptors
and their strings keep static storage duration.

Keep every current upstream table, including the empty Apple iOS model, and
preserve tag IDs, strings, public model mappings, and unknown-tag fallbacks.
Metadata initialization now performs zero allocations. In a native x86-64
measurement, the current tables previously retained 64,752 requested bytes in
1,349 allocations per initialized library instance.

Add a standalone metadata regression test covering all 16-bit tag IDs for every
registered model, sorted table invariants, reverse names, stable pointers,
unknown models, and fallback strings.
Replace metadata string pointers with compiler-computed 16-bit offsets.
Keep each model in its own constant pool so unused models can be discarded.
A compile-time bound prevents offset overflow; no generator, heap allocation
or runtime initialization is needed. Preserve the existing getters.

Move the table rows and their original attribution to TagLibData.h. Update
header dependencies and add exhaustive string, offset and lookup coverage.
Add an internal getTagFields method and use it at the ten callers that
request both strings. This avoids repeating model dispatch and binary
search. Keep the original three-argument getTagFieldName symbol as a
wrapper, and leave getTagDescription available.

Check both outputs for every model and 16-bit tag ID, including missing
descriptions, unknown tags and fallback buffers. Verify that the original
member-function signature and returned names are preserved.
@danoli3 danoli3 self-assigned this Nov 8, 2026
@danoli3
danoli3 self-requested a review November 8, 2026 12:18
@danoli3
danoli3 merged commit e594da9 into danoli3:master Nov 9, 2026
95 checks passed
@danoli3 danoli3 mentioned this pull request Nov 9, 2026
@andre-rosa
andre-rosa deleted the metadata-constant-string-pools branch November 10, 2026 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants