Skip to content

cripts: shrink Context from 3408 to 1920 bytes, expand data[] to 16#13195

Open
zwoop wants to merge 2 commits into
apache:masterfrom
zwoop:CriptsContext
Open

cripts: shrink Context from 3408 to 1920 bytes, expand data[] to 16#13195
zwoop wants to merge 2 commits into
apache:masterfrom
zwoop:CriptsContext

Conversation

@zwoop
Copy link
Copy Markdown
Contributor

@zwoop zwoop commented May 22, 2026

Pimpl Url::Path and Url::Query state behind unique_ptr so the heavy vector/unordered_map/cripts::string members only allocate when a script actually decomposes the path or query. Lazy-allocate Pristine, Parent, and Remap From/To URLs in _UrlBlock — they're rarely all touched, and the embedded 384-byte Url objects dominated the per-txn cost. Pimpl Error::Reason for the same reason. Drop the unused INET6_ADDRSTRLEN buffer in detail::ConnBase. Make cripts::Url's destructor virtual now that we delete via unique_ptr. Bump CONTEXT_DATA_SLOTS from 4 to 16 so scripts have room to stash more per-txn state — the 384-byte cost sits inside the budget freed by the URL/Connection cuts.

Pimpl Url::Path and Url::Query state behind unique_ptr so the heavy
vector/unordered_map/cripts::string members only allocate when a script
actually decomposes the path or query. Lazy-allocate Pristine, Parent,
and Remap From/To URLs in _UrlBlock — they're rarely all touched, and
the embedded 384-byte Url objects dominated the per-txn cost. Pimpl
Error::Reason for the same reason. Drop the unused INET6_ADDRSTRLEN
buffer in detail::ConnBase. Make cripts::Url's destructor virtual now
that we delete via unique_ptr. Bump CONTEXT_DATA_SLOTS from 4 to 16
so scripts have room to stash more per-txn state — the 384-byte cost
sits inside the budget freed by the URL/Connection cuts.
@zwoop zwoop added this to the 11.0.0 milestone May 22, 2026
@zwoop zwoop self-assigned this May 22, 2026
Copilot AI review requested due to automatic review settings May 22, 2026 22:23
@zwoop zwoop added the Cripts label May 22, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR reduces per-transaction cripts::Context footprint by lazily allocating heavier URL/query/path/error state only when accessed, and expands the per-txn Context::data[] slots to allow scripts to stash more state.

Changes:

  • PIMPL/lazy-allocate Url::Path and Url::Query internal state (segments / unordered_map / storage) and make their assignment operators return references.
  • Lazy-allocate rarely-used URL objects in Context (Pristine, Parent, Remap From/To) and Error::Reason via std::unique_ptr.
  • Increase CONTEXT_DATA_SLOTS to 16 and remove an unused INET6_ADDRSTRLEN buffer from detail::ConnBase.

Reviewed changes

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

Show a summary per file
File Description
src/cripts/Urls.cc Implements lazy URL slot allocation and moves path/query segment/param storage behind per-component state.
src/cripts/Error.cc Lazily allocates Error::_reason when setting a reason message.
src/cripts/Context.cc Resets lazy URL slots by releasing unique_ptrs between transactions.
include/cripts/Urls.hpp Introduces State pimpls for Path/Query, updates APIs, and makes Url destructor virtual.
include/cripts/Error.hpp Switches Error::_reason to std::unique_ptr<Reason>.
include/cripts/Context.hpp Expands Context::data[] slots and changes URL block members to unique_ptr for lazy creation.
include/cripts/Connections.hpp Removes an unused string buffer from detail::ConnBase.

Comment thread include/cripts/Urls.hpp
Bounds-check Path::Erase to avoid dereferencing a null _owner when
ix is out of range — operator[] returns a default-constructed String
in that case, and the subsequent p.operator=("") would then crash
inside String::operator=.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants