Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix large _.template memory consumption #203

Conversation

slickmb
Copy link
Contributor

@slickmb slickmb commented Feb 5, 2019

Problem: In order to support accepting a function for options.msg,
express-winston is calling _.template for every request. This compiles
a 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.

@bithavoc
Copy link
Owner

bithavoc commented Feb 5, 2019

❤️ Would you like to add yourself to AUTHORS?

**Problem:** In order to support accepting a function for options.msg,
express-winston is calling `_.template` for every request.  This compiles
a 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.
@slickmb slickmb force-pushed the pull/fix_template_compilation_memory_issues branch from 746f1ab to 60af475 Compare February 5, 2019 14:25
@slickmb
Copy link
Contributor Author

slickmb commented Feb 5, 2019

Sure! Thanks!

@bithavoc bithavoc merged commit 2af7b29 into bithavoc:master Feb 5, 2019
@bithavoc
Copy link
Owner

bithavoc commented Feb 5, 2019

Sick, thanks

@bithavoc
Copy link
Owner

bithavoc commented Feb 5, 2019

@slickmb Released in express-winston@3.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants