Skip to content

[sqllib] Experimental small string representation: store strings of 15 bytes or less inline - #8246

Draft
xiasongh wants to merge 4 commits into
mainfrom
song/small-string
Draft

xiasongh wants to merge 4 commits into
mainfrom
song/small-string

Conversation

@xiasongh

@xiasongh xiasongh commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Adds an opt-in small-string layout for SqlString. A string of 15 bytes or less is stored inline in a 16-byte value. Clone and drop of an inline string do not touch an atomic reference count. A longer string stays a reference-counted ArcStr.

SET FELDERA_SMALL_STRING = true;
  • The setting adds the small-string feature to feldera-sqllib in the generated pipeline Cargo.toml. Cargo unifies features, so every crate of the pipeline uses the same SqlString.
  • Off by default. With the setting off, SqlString is the same 8-byte ArcStr as on main.
  • Memory only. The rkyv and serde forms are the text, so the storage, checkpoint and wire formats do not change.
  • Option<SqlString> stays 16 bytes, because the length byte has niches.
  • An inline string is built with two overlapping loads, not a memcpy call (micro-benchmark, 0 to 15 bytes: 4.5 to 1.9 ns).

When to turn it on: most strings are 15 bytes or less (codes, flags, short IDs), and joins copy them into many rows. With long strings (for example UUID text), each string takes 16 bytes instead of 8, so it can be slower.

Describe Manual Test Plan

Unit tests in string.rs run with the feature on and off. The tests below compare the feature off (ddf46b83d4) with the feature on, with the same input. 8 workers.

Workload Where CPU End-to-end Peak RSS
SSB denormalization SF1 local -30% -27% n/a
SSB denormalization SF3 local -26% -24% same
SSB denormalization SF10 local -24% -17% n/a (memory limit)
QA ledger line items, 86 joins staging -18.2% -20.7% -20.5%
QA datagen aggregation local -12.8%
QA datagen joins local -8.1% -11%
QA event enrichment join staging -5.5% same (input bound) -11.5%
QA project tracking, 77 joins staging same (-0.9%) same +3.9%
QA levenshtein (long strings) local same (-1.5%)
  • Output: SSB SF1 lineorder_flat is byte-identical (5,998,347 rows). The final states of the local QA views are identical.
  • Feature off: a backfill micro-benchmark is the same as main (1648 vs 1692 ns/row).
  • The gain comes from strings of 15 bytes or less. A workload with mostly longer strings does not gain.

Checklist

  • Unit tests added/updated
  • Integration tests added/updated
  • Documentation updated
  • Changelog updated

Breaking Changes?

None. The feature is off by default, and the storage format does not change.

A string of 15 bytes or less is kept in the 16-byte SqlString, so clone
and drop do no atomic operations. A longer string stays an ArcStr.
Equality, order, hash, serde and rkyv are those of the text, so the
storage format does not change.

Adds the `string_rows` benchmark.

Signed-off-by: Song Huang <xiasongh@gmail.com>
Two overlapping loads in place of a copy of variable length. A string of
15 bytes or less is 1.4 to 2.3 times faster to build.

Signed-off-by: Song Huang <xiasongh@gmail.com>
Experimental. The `small-string` feature of feldera-sqllib selects the
16-byte inline SqlString. Without it, SqlString is an 8-byte ArcStr, as
before. `SET FELDERA_SMALL_STRING = true` makes the SQL compiler enable
the feature in the generated Cargo.toml.

Signed-off-by: Song Huang <xiasongh@gmail.com>
@mihaibudiu

Copy link
Copy Markdown
Contributor

Why not have this always-on?

@blp

blp commented Dec 4, 2026

Copy link
Copy Markdown
Member

There's a lot of work in Rust on so-called "German strings" along these lines. I just mention that to make sure that you (or Claude) looked at the prior art in the area.

@xiasongh

xiasongh commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

There's a lot of work in Rust on so-called "German strings" along these lines. I just mention that to make sure that you (or Claude) looked at the prior art in the area.

yep, this was inspired by german strings

@xiasongh xiasongh changed the title [sqllib] Opt-in small strings: store strings of 15 bytes or less inline [sqllib] Experimental small string representation: store strings of 15 bytes or less inline Dec 4, 2026
@xiasongh

xiasongh commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

Why not have this always-on?

there's some scenarios where it can be slower. my tests just show that it can be an improvement in some workloads

@xiasongh xiasongh assigned blp and unassigned blp Dec 4, 2026

This branch has not been deployed

No deployments
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