perf: cache default logger to avoid per-call reconstruction#72
Open
tylerbutler wants to merge 2 commits intomainfrom
Open
perf: cache default logger to avoid per-call reconstruction#72tylerbutler wants to merge 2 commits intomainfrom
tylerbutler wants to merge 2 commits intomainfrom
Conversation
Changelog PreviewThis PR adds the following changelog entries: v0.3.1 - 2026-02-22PerformanceCache default logger (#60)The default logger is now cached and only rebuilt when configuration changes via `configure()`, `set_level()`, or `reset_config()`. Previously it was reconstructed on every log call. |
tylerbutler
commented
Feb 22, 2026
README.md
Outdated
| } | ||
| ``` | ||
|
|
||
| > **Tip:** `import birch/meta as m` keeps metadata concise. All examples in this README use `m.` for brevity, but `meta.` works identically. |
Owner
Author
There was a problem hiding this comment.
Use GitHub formatted tips.
| let worker_logger = | ||
| log.new("myapp.worker") | ||
| |> log.with_context([#("worker_id", "worker-1"), #("queue", "high-priority")]) | ||
| |> log.with_context([meta.string("worker_id", "worker-1"), meta.string("queue", "high-priority")]) |
Owner
Author
There was a problem hiding this comment.
Would meta.str as an alias to meta.string be more less gleam like?
The default_logger() function was rebuilding a Logger from global config on every log call (reading persistent_term, chaining 4 builder calls). Now the logger is cached and only rebuilt when configure(), set_level(), or reset_config() is called. Closes #60
5cc5c72 to
b766759
Compare
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.
Summary
configure(),set_level(), orreset_config()is calledBefore
Every call to
birch.info(),birch.debug(), etc. would:persistent_term(Erlang) or module-level var (JS)Loggervia 4 builder callsAfter
First call builds and caches the logger. Subsequent calls return the cached value in O(1). Cache is invalidated only when config changes.
Closes #60
Test plan
reset_config()60+ times, confirming cache invalidation works