Skip to content

Conversation

@Zaczero
Copy link
Member

@Zaczero Zaczero commented Dec 27, 2025

assert(used <= maxSize);
res.resize(used);

Downsizing is essentially free whereas res.resize(i + 1) causes heavy memory realloc.

Also fixed a small bug where encodedLength(0) would return a really big number (no real imapct).

Plus made some minor type adjustments where made sense to me (size_t is more idiomatic for len/size).

Motivation

Context


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

@edolstra
Copy link
Member

edolstra commented Jan 5, 2026

Hm, where did the repeated allocation occur? Didn't the res.reserve(...) in decode() prevent that?

@Zaczero
Copy link
Member Author

Zaczero commented Jan 5, 2026

Agreed, I misunderstood the workings of resize (I'm new to C++). So I suppose the primary difference now is the performance of 1 bulk memset vs individual writes.

@xokdvium
Copy link
Contributor

xokdvium commented Jan 5, 2026

Where does the memset happen here?

@Zaczero
Copy link
Member Author

Zaczero commented Jan 5, 2026

std::string res(maxSize, '\0');

whereas resize writes null byte on each call to make it proper cstr.

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.

4 participants