util: amortise symbol_table_baset::next_unused_suffix#9083
Open
tautschnig wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR improves the performance of auto-generated symbol-name allocation by amortising symbol_table_baset::next_unused_suffix(prefix) using a per-prefix “next search-start” hint cache, avoiding repeated linear scans from 0.
Changes:
- Add a per-prefix suffix hint cache to
symbol_table_baset::next_unused_suffix(prefix)to amortise repeated allocations under the same prefix. - Remove
symbol_table_buildert’s now-redundantnext_unused_suffixoverride and reset the inherited cache onclear(). - Update namespace documentation and add a unit test covering the relaxed (non-minimal) suffix semantics, including behavior after erase.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| unit/util/symbol_table.cpp | Adds unit tests for increasing/unique suffix allocation under the new hint-cache semantics. |
| src/util/symbol_table.h | Ensures symbol_tablet::clear() also resets the inherited suffix hint cache. |
| src/util/symbol_table_builder.h | Removes duplicate per-prefix cache logic and relies on symbol_table_baset’s implementation. |
| src/util/symbol_table_base.h | Introduces the per-prefix suffix hint cache and updates next_unused_suffix(prefix) implementation + documentation. |
| src/util/namespace.h | Updates smallest_unused_suffix documentation to describe the now-stateful, non-minimal behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #9083 +/- ##
========================================
Coverage 80.68% 80.69%
========================================
Files 1714 1714
Lines 189593 189645 +52
Branches 73 73
========================================
+ Hits 152979 153037 +58
+ Misses 36614 36608 -6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
next_unused_suffix(prefix) restarted its linear scan from 0 on every call, so allocating N names that share a prefix (as the object factory does) costs O(N^2). Add a per-prefix "next search-start" hint to the base so repeated allocation under the same prefix is amortised O(1). The hint is looked up with try_emplace so the common cache-hit path does not construct/copy the prefix key. The returned suffix is now unused but no longer necessarily the smallest; no caller relies on minimality. This generalises a hint cache that symbol_table_buildert already maintained with the same relaxed semantics, so its now-redundant override (and duplicate cache) is removed; the builder resets the inherited cache on clear(), as does symbol_tablet. namespacet::smallest_unused_suffix's docstring is updated to describe the relaxed, now-stateful contract. It no longer over-claims a global cross-table guarantee: with multiple tables the result is the maximum of each table's per-table value, which is unused in every table only when the tables allocate suffixes monotonically from 0 (as auto-generated symbols do); the single-table common case yields a globally unused suffix. A thread-safety note is added to the base cache. Unit tests cover the new semantics: repeated allocation returns distinct increasing suffixes; uniqueness still holds after erase + re-allocation; clear() resets the hint so allocation restarts at 0; and the same holds through a symbol_table_buildert wrapper, exercising the inherited (no longer overridden) implementation and the builder's cache reset. Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
b8bc513 to
2fbecc3
Compare
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.
next_unused_suffix(prefix) restarted its linear scan from 0 on every call, so allocating N names that share a prefix (as the object factory does) costs O(N^2). Add a per-prefix "next search-start" hint to the base so repeated allocation under the same prefix is amortised O(1).
The returned suffix is now unused but no longer necessarily the smallest; no caller relies on minimality. This generalises a hint cache that symbol_table_buildert already maintained with the same relaxed semantics, so its now-redundant override (and duplicate cache) is removed; the builder resets the inherited cache on clear(), as does symbol_tablet. namespacet::smallest_unused_suffix's docstring is updated to describe the relaxed, now-stateful contract, and a thread-safety note is added to the base cache.
Add a unit test covering the new semantics: repeated allocation returns distinct increasing suffixes, and uniqueness still holds after erase + re-allocation under the same prefix.