perf(logging): strip debug log messages at compile-time (backport #4365)#4375
Merged
mergify[bot] merged 2 commits intov1.xfrom Oct 31, 2024
Merged
perf(logging): strip debug log messages at compile-time (backport #4365)#4375mergify[bot] merged 2 commits intov1.xfrom
mergify[bot] merged 2 commits intov1.xfrom
Conversation
partially close: #2847 Logging debug messages can lead to significant memory allocations, especially when outputting variable values. In Go, even if log_level is not set to debug, these allocations can still occur because the program evaluates the debug statements regardless of the log level. To prevent unnecessary memory usage, you can strip out all debug-level code from the binary at compile time using build flags. This approach improves the performance of CometBFT by excluding debug messages entirely, even when `log_level` is set to `debug`. This technique is ideal for production environments that prioritize performance optimization over debug logging. > Note: Compiling CometBFT with this method will completely disable all debug messages. If you require debug output, avoid compiling the binary with these settings. In order to build a binary stripping all debug log messages (e.g. `log.Debug()`) from the binary, use the `nodebug` tag: ``` COMETBFT_BUILD_OPTIONS=nodebug make install ``` once it's installed you can run a `kvstore` example with `log_level = "debug"` set in the `config.toml` and you will see that no debug messages are shown in the log. cc: @ValarDragon #### PR checklist - [ ] ~~Tests written/updated~~ - [X] Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog) - [X] Updated relevant documentation (`docs/` or `spec/`) and code comments --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> (cherry picked from commit 51e9948)
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.
partially close: #2847
Logging debug messages can lead to significant memory allocations, especially when outputting variable values. In Go, even if log_level is not set to debug, these allocations can still occur because the program evaluates the debug statements regardless of the log level.
To prevent unnecessary memory usage, you can strip out all debug-level code from the binary at compile time using build flags. This approach improves the performance of CometBFT by excluding debug messages entirely, even when
log_levelis set todebug. This technique is ideal for production environments that prioritize performance optimization over debug logging.In order to build a binary stripping all debug log messages (e.g.
log.Debug()) from the binary, use thenodebugtag:once it's installed you can run a
kvstoreexample withlog_level = "debug"set in theconfig.tomland you will see that no debug messages are shown in the log.cc: @ValarDragon
PR checklist
Tests written/updated.changelog(we use unclog to manage our changelog)docs/orspec/) and code commentsThis is an automatic backport of pull request #4365 done by [Mergify](https://mergify.com).