Fix large _.template memory consumption #203
Merged
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.
Problem: In order to support accepting a function for options.msg,
express-winston is calling
_.template
for every request. This compilesa brand new lodash template every request. Under heavy load, this has
significant performance and memory usage implications.
Solution: During initialization, make the decision on whether to use
a single cached template or a dynamic function that compiles a template
for each request. This way, we get the efficiency of a precompiled
template for the more common use cases, while remaining backwards
compatible with published features.
In a future version, it might be worth considering dropping support
for mustache formatting and just have express-winston consumers always
provide a function if they want a custom options.msg. The api consumer
can use JS template literals if they need templating in their custom
message.