bithavoc / express-winston

express.js middleware for winstonjs
https://www.npmjs.com/package/express-winston
MIT License
796 stars 187 forks source link

Fix large _.template memory consumption #203

Closed slickmb closed 5 years ago

slickmb commented 5 years ago

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 commented 5 years ago

❤️ Would you like to add yourself to AUTHORS?

slickmb commented 5 years ago

Sure! Thanks!

bithavoc commented 5 years ago

Sick, thanks

bithavoc commented 5 years ago

@slickmb Released in express-winston@3.1.0