Skip to content

perf(value): back KeyString with SmolStr for zero-alloc inline key storage#1825

Open
thomasqueirozb wants to merge 6 commits into
mainfrom
perf/smol-str-keystring
Open

perf(value): back KeyString with SmolStr for zero-alloc inline key storage#1825
thomasqueirozb wants to merge 6 commits into
mainfrom
perf/smol-str-keystring

Conversation

@thomasqueirozb

@thomasqueirozb thomasqueirozb commented Jun 17, 2026

Copy link
Copy Markdown
Member

Summary

KeyString is now backed by SmolStr instead of String. Strings up to 22 bytes are stored inline in the struct (no heap allocation). All common event key names (regex capture group names, log field names like message/host/timestamp) fit within that limit, so clone() becomes a plain 24-byte stack copy instead of a malloc + memcpy.

Benchmarked on two Vector test harness workloads (5x c5.large producers -> 1x c5.large subject -> consumer, 60s measurement window):

Benchmark Before After Delta
regex_parsing_performance 18.3 MiB/s 20.5 MiB/s +12%
real_world_1_performance 18.2 MiB/s 19.7 MiB/s +8%

Change Type

  • Bug fix
  • New feature
  • Non-functional (chore, refactoring, docs)
  • Performance

Is this a breaking change?

  • Yes
  • No

How did you test this PR?

Ran the Vector regex_parsing_performance and real_world_1_performance integration benchmarks (5x c5.large producers -> 1x c5.large Vector -> consumer, 60s measurement window). Confirmed all existing VRL unit tests pass.

Does this PR include user facing changes?

  • Yes. Please add a changelog fragment based on our guidelines.
  • No. A maintainer will apply the "no-changelog" label to this PR.

Checklist

References

NA

thomasqueirozb and others added 4 commits June 17, 2026 15:14
SmolStr doesn't implement proptest::arbitrary::Arbitrary, so the
proptest_derive macro fails. Replace the derive with a manual impl
that maps any::<String>() through KeyString::from.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
pront
pront previously approved these changes Jun 17, 2026

@pront pront left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice. I shared some concerns offline, so let's wait until we have an SMP and results are well understood before merging.

`BorrowedSegment::Field` wraps a `Cow<'_, str>` which is always
`Borrowed` when constructed from the `path!()` macro. Previously
`field.to_string().into()` allocated a transient `String` only to
immediately copy it into a `KeyString` and drop it. With SmolStr-backed
`KeyString`, `From<Cow<'_, str>>` goes directly to `SmolStr::new` —
inline for keys ≤22 bytes, no heap allocation involved.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@bruceg

bruceg commented Jun 18, 2026

Copy link
Copy Markdown
Member

Did you look into any of the other "small string" crates like compact_str or smartstring?

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