goatshriek / stumpless

a C logging library built for high performance and a rich feature set
https://goatshriek.github.io/stumpless
Apache License 2.0
443 stars 321 forks source link

remove `snprintf` from `stumpless_get_prival_string` #435

Closed goatshriek closed 1 month ago

goatshriek commented 1 month ago

The existing implementation of stumpless_get_prival_string makes use of snprintf to build the resulting string, but a simple memcpy scheme would likely be more performant. This change is to refactor the function to do this, and verify that performance has improved.

General Approach

There are a few details left out of the following approach, for you to fill in as you encounter them. If you find you need help, please ask here or on the project gitter and someone can help you get past the stumbling block.

Before you make any changes, make sure that you can run the performance tests, specifically the GetPrivalString benchmark. Make sure that you can collect performance both before and after you implement your change. You should see Time/CPU cycles decrease as a result - if you do not, review your implementation and find out why. You can find details on running the performance benchmarks in stumpless in the docs/benchmark.md documentation.

The change itself is straightforward - the function in question is in src/prival.c.

Once you have this, make your changes and make sure that performance improves as expected! The test suites should continue to pass and coverage should not decrease as a result of your changes - you may need to add more tests for the refactored function to test/function/prival.cpp improve coverage depending on your implementation.

EDIT: Originally this issue stated that memory allocations would decrease as part of this change, but as pointed out by @Caselhos this is not true - the change only affects CPU usage.

Caselhos commented 1 month ago

Hello, is this still available to try? trying to do this process for the first time.

Thanks in advance.

goatshriek commented 1 month ago

Yes it is; I will assign it to you so that you can work through it. Good luck!