Files
scylladb/cql3
Yaniv Michael Kaul 05f36422d8 cql3: replace shared_ptr with unique_ptr for column operations
Motivation:
The prepared statement cache is memory-bounded. Every byte saved per
prepared statement means more statements can fit in the cache before
evictions occur. Cache evictions force re-preparation of statements,
which is expensive (schema lookups, type checking, optimization). Workloads
with many distinct prepared statements (multi-tenant, ORM-generated queries)
benefit directly from smaller per-statement memory footprint.

Nature of change:
The _column_operations vector in modification_statement holds polymorphic
operation objects (setters, adders, deleters, etc.) via seastar::shared_ptr,
but these objects are never shared — each is created during prepare(),
stored in the vector, and only accessed by reference during execution.

Replace shared_ptr<operation> with unique_ptr<operation> throughout:
- operation::raw_update::prepare() return type
- operation::raw_deletion::prepare() return type
- modification_statement::add_operation() parameter
- modification_statement::_column_operations vector element type
- All make_shared<T>(...) → std::make_unique<T>(...)

Memory savings:
seastar::make_shared wraps each object in shared_ptr_count_for<T>, which
prepends a vtable pointer (8 bytes) + refcount (8 bytes) = 16 bytes
overhead per operation. A typical INSERT/UPDATE has 3-5 column operations,
saving 48-80 bytes per prepared statement. This allows
statements to fit in the cache to fit in the cache for a typical workload (assuming 2KB
average prepared statement size).

unique_ptr also makes ownership semantics explicit in the type system.

Performance: perf_cql_parser shows no regression (110K tps).

Signed-off-by: Yaniv Kaul <yaniv.kaul@scylladb.com>
AI-assisted: Yes
Backport: no, improvement

Closes scylladb/scylladb#30010
2026-06-03 23:16:45 +03:00
..
2026-04-12 19:46:33 +03:00
2026-04-12 19:46:33 +03:00
2026-04-12 19:46:33 +03:00
2026-04-12 19:46:33 +03:00
2026-04-12 19:46:33 +03:00
2026-04-12 19:46:33 +03:00
2026-04-12 19:46:33 +03:00
2026-04-12 19:46:33 +03:00
2026-04-12 19:46:33 +03:00
2026-04-12 19:46:33 +03:00
2026-04-12 19:46:33 +03:00
2026-04-12 19:46:33 +03:00
2026-04-12 19:46:33 +03:00
2026-04-12 19:46:33 +03:00
2026-04-12 19:46:33 +03:00
2026-04-12 19:46:33 +03:00
2026-04-12 19:46:33 +03:00
2026-04-12 19:46:33 +03:00
2026-04-12 19:46:33 +03:00
2026-04-12 19:46:33 +03:00
2026-04-12 19:46:33 +03:00
2026-04-12 19:46:33 +03:00