goatshriek / stumpless

a C logging library built for performance and features
https://goatshriek.github.io/stumpless
Apache License 2.0
446 stars 335 forks source link

refactor prival from string for performance #428

Closed goatshriek closed 1 month ago

goatshriek commented 3 months ago

While the stumpless_prival_from_string function works, it currently allocates and later frees heap memory for temporary storage of strings during parsing. Now that #385 and #383 have been implemented, this function should be refactored so that it uses the new _from_buffer functions for facility and enum parsing to avoid heap memory allocations.

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.

Review the documentation for stumpless_get_facility_enum_from_buffer and stumpless_get_severity_enum_from_buffer so that you understand how they work, and then understand how stumpless_prival_from_string in src/prival.c currently works. This is the function you will be reworking.

Before you make any changes, make sure that you can run the performance tests, specifically the PrivalFromString benchmark. Make sure that you can collect performance both before and after you implement your change. You should see CPU cycles and memory allocated 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.

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.

Griezn commented 2 months ago

Hey, I would like to solve this issue. Could you assign me to it?

goatshriek commented 2 months ago

Sure thing, good luck!