perf(http): cut per-request allocs (buffer memset, header keys, empty tables - #698
Open
jmgomez wants to merge 4 commits into
Open
perf(http): cut per-request allocs (buffer memset, header keys, empty tables#698jmgomez wants to merge 4 commits into
jmgomez wants to merge 4 commits into
Conversation
jmgomez
commented
Jul 22, 2026
Contributor
arnetheduck
reviewed
Jul 31, 2026
| proc set*(ht: var HttpTables, key: string, value: string) = | ||
| ## Set/replace value of header with key ``key`` to value ``value``. | ||
| let lowkey = key.toLowerAscii() | ||
| let lowkey = lowerKey(key) |
Member
There was a problem hiding this comment.
this will still perform several unnecesary allocations - what you're looking for is:
proc replaceWithOne(v: var seq[string], s: string) =
v.setLen(1)
v[0] = s
ht.table[lowerKey(...)].replaceWithOne()the values here should also use chronosSink and move into the seq
arnetheduck
reviewed
Jul 31, 2026
arnetheduck
reviewed
Jul 31, 2026
arnetheduck
reviewed
Jul 31, 2026
arnetheduck
reviewed
Aug 11, 2026
| conn.buffer.setLen(res) | ||
| let header = parseRequest(conn.buffer) | ||
| let header = parseRequest( | ||
| conn.buffer.toOpenArray(0, res - 1), makeCopy = true) |
Member
There was a problem hiding this comment.
it might be that we don't need the makecopy here - afair, parseRequest will store offsets into the buffer so as long as the buffer is not touched, its length should really not matter
arnetheduck
reviewed
Aug 27, 2026
| ## response has no streaming writer — on that path closeWait() never | ||
| ## actually suspends, so the future allocation is pure overhead. | ||
| ## Returns false when the async variant is required. | ||
| if req.state == HttpState.Alive: |
Member
There was a problem hiding this comment.
instead of repeating this code, this should be refactored to something like:
template closeImpl(..) =
if ...
``
then the template can be inlined in both the public closeWait and the other places - this should achieve the same goal but with less future maintenance - the state management is hairy enough as it is.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.