tree: 98ed60d1b59bcb8002dc2efc9f5543ef25c57f9b [path history] [tgz]
  1. src/
  2. BUILD.gn
  3. METADATA.textproto
  4. OWNERS
  5. README.md
src/lib/flyweights/README.md

flyweights

Types implementing the flyweight pattern for reusing object allocations. See the crate's documentation for details on the approach taken and tradeoffs to consider.

Comparison to other crates

As of January 2023, there did not appear to be any popular external crates for interning which fit all of our requirements:

  • global synchronization limited to creating the values, not required for reading them once created
  • offers a short string optimization (SSO)
  • types implement Send and Sync
  • frees allocations for unused strings incrementally without spiking (no GC)
  • limited usage of unsafe
  • recently maintained, some dependents in the ecosystem

Alternatives evaluated along with reasons for rejection:

  • arc-string-interner
    • no way to free unused strings
    • no SSO possible
  • intaglio
    • no way to free unused strings
    • no SSO possible
  • intern-arc
    • no SSO possible
    • lots of unsafe code to support features we don't need
  • internment (& a fork arc-interner)
    • no SSO possible
    • large transitive dependencies with lots of unsafe
  • internship
    • types can't be used across multiple threads
  • lasso
    • no way to free unused strings
  • refcount-interner
    • requires manually calling shrink_to_fit() on the interner instead of freeing unused strings as their references are dropped, too expensive to call on every Drop
  • string-intern
    • no updates for 5 years, is marked as beta in its readme
  • string-interner
    • no way to free unused strings
  • symbol_interner
    • no way to free unused strings
  • symtern
    • no way to free unused strings