ankane / logstop

Keep personal data out of your logs
MIT License
240 stars 13 forks source link

Mutate message to reduce memory allocation #5

Closed guigs closed 4 years ago

guigs commented 4 years ago

Logging is a hotspot and some log messages can be quite big and each call to gsub allocates a new string.

I added a call to #dup at the beginning so we don't mutate the original message. But after that all substitutions mutates this copy.

Disclaimer

I haven't run any benchmarks and have not tested this.

ankane commented 4 years ago

Thanks @guigs! rake benchmark:memory shows a decrease of 5 allocations per log call as expected.