Skip to content

util: amortise symbol_table_baset::next_unused_suffix#9083

Open
tautschnig wants to merge 1 commit into
diffblue:developfrom
tautschnig:cleanup/symbol-table-next-unused-suffix
Open

util: amortise symbol_table_baset::next_unused_suffix#9083
tautschnig wants to merge 1 commit into
diffblue:developfrom
tautschnig:cleanup/symbol-table-next-unused-suffix

Conversation

@tautschnig

@tautschnig tautschnig commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

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.

  • Each commit message has a non-empty body, explaining why the change was made.
  • Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • n/a The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • n/a White-space or formatting changes outside the feature-related changed lines are in commits of their own.

@tautschnig tautschnig self-assigned this Jun 24, 2026
Copilot AI review requested due to automatic review settings June 24, 2026 08:42

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-redundant next_unused_suffix override and reset the inherited cache on clear().
  • 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.

Comment thread src/util/symbol_table_base.h Outdated
Comment thread src/util/namespace.h Outdated
@codecov

codecov Bot commented Jun 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.69%. Comparing base (7483d0d) to head (2fbecc3).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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>
@tautschnig tautschnig force-pushed the cleanup/symbol-table-next-unused-suffix branch from b8bc513 to 2fbecc3 Compare June 24, 2026 13:42
@tautschnig tautschnig assigned kroening and unassigned tautschnig Jun 24, 2026
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.

3 participants