Skip to content

feat(internity): introduce string interning crate#604

Open
geeknoid wants to merge 1 commit into
mainfrom
internity
Open

feat(internity): introduce string interning crate#604
geeknoid wants to merge 1 commit into
mainfrom
internity

Conversation

@geeknoid

@geeknoid geeknoid commented Jul 24, 2026

Copy link
Copy Markdown
Member

Add compact single-threaded and concurrent string interners with frozen, lock-free readers, no-std and Serde support, property tests, Loom models, and Criterion, Gungraun, and memory benchmarks.

Lookup benchmarks use 60,000 distinct identifier-like strings via INTERNITY_BENCH_CORPUS_SIZE=60000; memory benchmarks use the default 6,000 strings. Lower is better.

Lookup implementation Time
internity (live) 234.85 us
internity (frozen) 214.25 us
lasso 236.60 us
string-interner 309.74 us
symbol_table 574.28 us
string_cache 269.66 us
Memory implementation Handle Filled Lookup
internity Lexicon 4 B 172.0 KiB 96.5 KiB
internity ThreadedLexicon 4 B 181.1 KiB 98.8 KiB
lasso 4 B 264.2 KiB 224.2 KiB
string-interner 4 B 204.0 KiB 204.0 KiB
symbol_table 4 B 241.3 KiB 241.3 KiB
string_cache 8 B 351.7 KiB 351.7 KiB

Copilot AI review requested due to automatic review settings July 24, 2026 14:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Introduces a new internity crate providing compact string interning with both a single-threaded (Lexicon) and concurrent (ThreadedLexicon) implementation, plus a frozen Reader for fast lock-free resolution. The PR also adds extensive tests, benchmarks, and performance documentation to support correctness and compare against other Rust interners.

Changes:

  • Added internity crate (no-std + alloc baseline, optional std for concurrency, optional serde) with Sym handles and a sealed Reader abstraction.
  • Added correctness coverage via integration tests, property tests (Bolero), and concurrency modeling (Loom).
  • Added benchmarking + reporting tooling (Criterion, Gungraun/Callgrind, memory footprint harness) and performance/comparison docs.

Reviewed changes

Copilot reviewed 30 out of 33 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
README.md Adds internity to the repo’s primary crates list.
CHANGELOG.md Links the new internity crate changelog from the workspace changelog index.
Cargo.toml Adds workspace dependency entries needed by internity (and competitors used in benches).
Cargo.lock Records resolved dependencies for the new crate and benchmark competitors.
.spelling Adds terminology used by internity docs/code (e.g., CSR, dedup, sharded).
crates/internity/Cargo.toml Defines the new crate’s features, dependencies, benches, and Loom test target.
crates/internity/src/lib.rs Crate root: public API exports, feature gating, and high-level documentation.
crates/internity/src/lexicon.rs Implements the single-threaded interner with dense Sym encoding + freeze to Reader.
crates/internity/src/threaded_lexicon.rs Implements the concurrent sharded interner and freeze-to-reader logic.
crates/internity/src/sym.rs Defines Sym handle representation and encoding/decoding helpers.
crates/internity/src/reader.rs Defines the sealed Reader trait for frozen, thread-safe resolution.
crates/internity/src/flat_reader.rs Frozen reader implementation for Lexicon’s dense layout.
crates/internity/src/shard.rs Shard wrapper using RwLock/upgradable-read for concurrent interning.
crates/internity/src/shard_write.rs Shard write-state: dedup table + CSR offsets + byte buffer.
crates/internity/src/shard_reader.rs Frozen per-shard storage and resolution routine.
crates/internity/src/sharded_reader.rs Frozen reader implementation for ThreadedLexicon (shard + local decode).
crates/internity/src/storage.rs Centralizes unchecked UTF-8 reconstruction for fast resolve paths.
crates/internity/src/symbol_map.rs Adds Sym-keyed map/set support via a specialized hasher.
crates/internity/src/serde_impls.rs Implements serde for Sym and interners (feature-gated).
crates/internity/tests/basic.rs Broad integration tests covering API behavior, freezing, concurrency, serde, etc.
crates/internity/tests/bolero_internity.rs Property tests for dedup/resolve/freezing and raw-handle range checks.
crates/internity/tests/loom_internity.rs Loom model tests for concurrent dedup and snapshot behavior.
crates/internity/benches/compare.rs Criterion wall-clock benchmark suite comparing multiple interners and thread counts.
crates/internity/benches/counts/main.rs Gungraun/Callgrind harness entrypoint (Linux-only runner).
crates/internity/benches/counts/linux.rs Deterministic instruction/cache-count benches for hot paths + competitors.
crates/internity/benches/mem.rs Memory footprint benchmark using a tracking global allocator.
crates/internity/scripts/perf_report.rs Script to run benches and regenerate docs/PERF.md.
crates/internity/docs/PERF.md Generated performance report output committed to the repo.
crates/internity/docs/COMPARISON.md Detailed comparative analysis across the Rust string interner ecosystem.
crates/internity/README.md Crate README content for docs.rs / GitHub browsing.
crates/internity/CHANGELOG.md Per-crate changelog for internity.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/internity/scripts/perf_report.rs
Comment thread crates/internity/src/sharded_reader.rs
Comment thread crates/internity/src/lexicon.rs Outdated
Copilot AI review requested due to automatic review settings July 24, 2026 14:52
@github-actions

github-actions Bot commented Jul 24, 2026

Copy link
Copy Markdown

✅ Version increments look sufficient

cargo semver-checks compared the 2 crate(s) this PR publishes against their previous version-bump commit in git history. Every version increment is sufficient for the detected API changes.

Crate Baseline Baseline commit This PR Minimum required Status
internity new crate 0.1.0 0.1.0 ✅ ok
internity_macros new crate 0.1.0 0.1.0 ✅ ok

This check is informational and does not block the merge.

View the check run

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 32 out of 33 changed files in this pull request and generated 2 comments.

Comment thread crates/internity/src/storage.rs Outdated
Comment thread crates/internity/tests/basic.rs Outdated
Copilot AI review requested due to automatic review settings July 24, 2026 14:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 32 out of 33 changed files in this pull request and generated 2 comments.

Comment thread crates/internity/src/sym.rs Outdated
Comment thread crates/internity/benches/compare.rs
Copilot AI review requested due to automatic review settings July 24, 2026 15:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 32 out of 33 changed files in this pull request and generated no new comments.

@codecov

codecov Bot commented Jul 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.0%. Comparing base (fa49a45) to head (9d8393d).

Additional details and impacted files
@@           Coverage Diff            @@
##             main     #604    +/-   ##
========================================
  Coverage   100.0%   100.0%            
========================================
  Files         442      459    +17     
  Lines       42616    43546   +930     
========================================
+ Hits        42616    43546   +930     
Flag Coverage Δ
linux 100.0% <100.0%> (ø)
linux-arm 100.0% <100.0%> (ø)
scheduled ?
windows 100.0% <100.0%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.

Copilot AI review requested due to automatic review settings July 24, 2026 15:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 33 out of 34 changed files in this pull request and generated 2 comments.

Comment thread crates/internity/src/storage.rs Outdated
Comment thread justfiles/anvil/checks/bolero.just
Copilot AI review requested due to automatic review settings July 24, 2026 15:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 33 out of 34 changed files in this pull request and generated 2 comments.

Comment thread crates/internity/docs/COMPARISON.md Outdated
Comment thread crates/internity/src/lib.rs
Copilot AI review requested due to automatic review settings July 24, 2026 15:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 33 out of 34 changed files in this pull request and generated 2 comments.

Comment thread justfiles/anvil/checks/bolero.just
Comment thread crates/internity/benches/counts/linux.rs
Copilot AI review requested due to automatic review settings July 24, 2026 15:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 43 out of 44 changed files in this pull request and generated 1 comment.

Comment thread crates/internity/src/serde_impls.rs Outdated
Copilot AI review requested due to automatic review settings July 24, 2026 22:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 43 out of 44 changed files in this pull request and generated 1 comment.

Comment thread crates/internity/tests/derive_regressions.rs
Copilot AI review requested due to automatic review settings July 25, 2026 02:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 43 out of 44 changed files in this pull request and generated 1 comment.

Comment thread crates/internity/tests/basic.rs
Copilot AI review requested due to automatic review settings July 25, 2026 02:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 43 out of 44 changed files in this pull request and generated 1 comment.

Comment thread crates/internity/src/sym.rs Outdated
Copilot AI review requested due to automatic review settings July 25, 2026 02:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 43 out of 44 changed files in this pull request and generated 3 comments.

Comments suppressed due to low confidence (2)

crates/internity/src/de/mod.rs:48

  • The reference-style rustdoc links include ThreadedLexicon, which is not available without the std feature. This creates broken intra-doc links in serde-only (no_std) builds. After switching the earlier prose to non-linked ThreadedLexicon text, these reference links can be removed.
//! [`Sym`]: crate::Sym
//! [`Lexicon`]: crate::Lexicon
//! [`LocalLexicon`]: crate::LocalLexicon
//! [`ThreadedLexicon`]: crate::ThreadedLexicon

crates/internity/src/de/deserialize_in.rs:26

  • The reference-style links for ThreadedLexicon/ThreadedLexicon::deserialize_in are broken when the std feature is off. Since the prose can avoid linking to ThreadedLexicon, these reference links should be removed to keep rustdoc clean in no_std builds.
/// [`Lexicon`]: crate::Lexicon
/// [`LocalLexicon`]: crate::LocalLexicon
/// [`LocalLexicon::deserialize_in`]: crate::LocalLexicon::deserialize_in
/// [`ThreadedLexicon`]: crate::ThreadedLexicon
/// [`ThreadedLexicon::deserialize_in`]: crate::ThreadedLexicon::deserialize_in

Comment thread crates/internity/src/de/mod.rs
Comment thread crates/internity/src/de/deserialize_in.rs
Comment thread crates/internity/src/lib.rs
Copilot AI review requested due to automatic review settings July 25, 2026 03:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 43 out of 44 changed files in this pull request and generated no new comments.

@geeknoid
geeknoid enabled auto-merge (squash) July 25, 2026 14:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 43 out of 44 changed files in this pull request and generated 1 comment.

Comment thread crates/internity/src/shard.rs Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 43 out of 44 changed files in this pull request and generated no new comments.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 43 out of 44 changed files in this pull request and generated no new comments.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 45 out of 46 changed files in this pull request and generated 8 comments.

Comments suppressed due to low confidence (2)

crates/internity/src/sym.rs:100

  • The workspace lints enable clippy::unwrap_used, so this expect(...) triggers a warning (and CI denies warnings). Add an explicit #[expect(clippy::unwrap_used, reason = ...)] documenting that exceeding the u32 capacity is treated as a programming error / documented panic condition.
    crates/internity/src/local_lexicon.rs:203
  • The workspace lints enable clippy::unwrap_used, so this expect(...) triggers a warning (and CI denies warnings). Add an explicit #[expect(clippy::unwrap_used, reason = ...)] on resolve to document that this is the intentional panicking variant.
    #[inline]
    #[must_use]
    pub fn resolve(&self, sym: Sym) -> &str {
        self.try_resolve(sym).expect("internity: Sym does not belong to this interner")

Comment thread crates/internity/tests/basic.rs
Comment thread crates/internity/tests/serde_in.rs
Comment thread crates/internity/tests/derive_regressions.rs
Comment thread crates/internity/src/sym.rs
Comment thread crates/internity/src/reader.rs
Comment thread crates/internity/src/local_lexicon.rs
Comment thread crates/internity/src/shard_write.rs
Comment thread crates/internity/src/sharded_reader.rs
Add compact local and concurrent string interners with frozen, lock-free
readers, no-std and Serde support, property tests, Loom models, and Criterion,
Gungraun, and memory benchmarks.

Add interner-aware deserialization so items can deserialize directly into a
chosen LocalLexicon or ThreadedLexicon while converting string fields to Sym
handles.

Lookup benchmarks use 60,000 distinct identifier-like strings via
`INTERNITY_BENCH_CORPUS_SIZE=60000`; memory benchmarks use the default
6,000 strings. Lower is better.

| Lookup implementation | Time |
|---|---:|
| internity (live) | 234.85 us |
| internity (frozen) | 214.25 us |
| lasso | 236.60 us |
| string-interner | 309.74 us |
| symbol_table | 574.28 us |
| string_cache | 269.66 us |

| Memory implementation | Handle | Filled | Lookup |
|---|---:|---:|---:|
| internity LocalLexicon | 4 B | 172.0 KiB | 96.5 KiB |
| internity ThreadedLexicon | 4 B | 181.1 KiB | 98.8 KiB |
| lasso | 4 B | 264.2 KiB | 224.2 KiB |
| string-interner | 4 B | 204.0 KiB | 204.0 KiB |
| symbol_table | 4 B | 241.3 KiB | 241.3 KiB |
| string_cache | 8 B | 351.7 KiB | 351.7 KiB |

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: df123253-43b0-4ae3-82c1-6e9f88846881

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 45 out of 46 changed files in this pull request and generated no new comments.

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