Repository navigation
Logger: allocate nothing when the level filters every line out - #1456
Merged
Merged
Conversation
At info level Amber::Pipe::Logger built every line before Log dropped it: the time stamp, each header, cookie and param line, and the session (which it also created on pipelines without one). It allocated 11.8 KB per request while writing nothing. The pipe now holds its Log sources and checks their level first; when no source writes debug lines it only passes the request on. When it does write, each line is built inside the Log block and headers are walked in place.
This was referenced Nov 21, 2026
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.
Amber::Pipe::Loggerbuilt every debug line beforeLogdropped it, so at the defaultinfolevel it wrote nothing yet allocated about 11.8 KB per request. It also parsed the params and created a session on pipelines that have none.The pipe now holds its
Logsources and checks their level first. When no source writes debug lines, it passes the request on and allocates nothing: no clock read, no params, no session. When it does write, each line is built inside theLogblock, and headers are read in place instead of copied into a hash.Measurements
Harness:
home-page-memory-bench(mem.rb) on an app from Amber CLI main (2.0.11 template) with the Post scaffold and 50 seeded rows,crystal-alpha build --release(Crystal 1.21.0, LLVM 21.1.8), arm64 macOS, production mode, one process. Route/b/logger/full: the home page fully rendered through Error, SecurityHeaders and Logger. Before = amber v2-dev 814705e, after = this branch. Six rounds per side, interleaved in ABBA order; medians shown. Load runs: oha, 32 connections, 20 s, starting heap 0. The machine was shared with other heavy jobs (load average 40 to 110), so requests/s is approximate; bytes per request is exact.The after build allocates exactly what the same render allocates without the Logger pipe (22,745 bytes per request on
/b/lean/full).Specs
allocates nothing when the level filters every line out: 100 calls atinfolevel add 0 bytes (the old pipe: 550,256 bytes, so the spec fails against it).writes the request, header, cookie and param lines at debug level, with the filter and skip lists.