-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Some of the performance items #31
Comments
Provide source on this statement please. Because as far as I know |
It was an article I read years back. I'll look for it in a while, don't wanna look like I'm going off task at work haha |
I can't find the original article, but here's some sources:
|
Apart from the articles you posted already, there are performance implications when using process.env directly hence it might be useful to look into dependencies that wrap process.env to ensure to overcome these implications |
@gerardmrk sounds like a great start for the performance section. Maybe create a new branch, start writing that section and get your name on the credit wall once we upload it? |
I checked right now. Reading process.env is five times slower than reading copy. You can do it only 3600 times per milisecond. |
that's definitely an important point for the performance section! |
FWIW |
@BrunoScheufler @mscdex what other ideas we have for performance bullets? can we fill a section of ~7 items? |
@i0natan Performance (micro optimizations or otherwise) can vary between versions of V8. So for example, some optimizations for versions of node using V8's Crankshaft optimizing compiler will be very different than those optimizations for V8's TurboFan. Even between V8 versions using the same optimizing compiler there can be dramatic changes in performance, especially as the V8 team incrementally adds fast paths that existed with Crankshaft to TurboFan and improves performance on new language features. So if you were to include such things, you might want to at least include the node/V8 versions that the optimization applies to (or has been tested with). |
@i0natan I'll do it after 5pm NZ time, but I'd rather you reword any points I add in the pull request because I am bad with forming coherent statements that is easily understandable and to the point |
Another one I'd add is, avoid pure functional programming in very performance-critical services (e.g. chaining multiple |
I thought I heard some time back V8 might be able to optimize the functional stuff to essentially be a regular loop, at least in some scenarios. Until then, I would also advocate non-functional (array) methods for hot code. |
what v8 does now when I chain array utils like map, filter? why is it worst than looping over it myself? @gerardmrk we are now very focused on improving the current sections, let's publish the performance section in few weeks. In the interim, we can collect many ideas (e.g. fast logger, express-cache, node_env=production, detect sync API usages using the flag warn-async, etc), form a solid list and then publish. does this make sense? |
@i0natan immutable
the example creates a receipt object but in between that would've create 5 arrays total. This is readable, maintainable, and less prone to bugs. But if your receipts array is huge and gets called very often (i.e. heavy-traffic), it's worth thinking about sacrificing the above mentioned benefits and just mutate the array in-place, but annotating it more to offset complexity if working in a team. what @mscdex said, its possible V8 is doing JIT on chains like this, I have yet to research that though, and he could be right. I've been caught up with work, I'll create the branch today after work, sorry! |
@i0natan also feel free to create the branch yourself and add the points if I'm taking too slow to do it, I am not fussed about not taking credits for all these, I'm just doing this cos I want to highlight important performance tips for the Node community because performance is usually a second class citizen |
@gerardmrk your explanation was great, I think u belong here :) |
Performance section will be added to our milestones in the next couple of days, there will group all the performance advice |
Not sure if hijacking this issue is the right approach, but I'll start here and move if that makes more sense. This may sound silly and pretty obvious, but upgrading your apps to the latest LTS as soon as possible to take advantage of V8 improvements. Teams often get so bogged down by bugs/features, that doing something like this is always gets back burnered. With respect to the functional/immutable comments above: I've found that working with JS data structures in an immutable way has significantly improved application performance. While it may seem counter-intuitive in terms of working with completely new objects/values, when operating inside of complex loops/algorithms it has made both understanding what's happening to the data far easier to comprehend in context, as well you avoid scenarios where mutations can leak, be far reaching and difficult to trace. My team has successfully adopted this approach with one of our production APIs, and found it significantly improved performance, but I suppose YMMV. We then took it a step further and use @substack's deep-freeze module as a simple safe guard against mutations. This is one example I have, I'll see about digging up some more and/or finding decent articles that help make this more than just anecdotal :) . |
@snypelife I can see why working with immutable can make the code more simple, but isn't [1,2,3].map(...).reduce(...) slower than imperative code? |
some ideas
|
@sebs can u kindly clarify the first two? they both sound interesting but I'm not 100% sure I understood |
Agree that we should avoid "repeatedly processing identical steps that give the same result" |
@i0natan Processing
|
I'd be not so sure about that over all engines for all time. And I would really like to check out, if chaining vs. assigning each result to a new var is maybe a difference. |
@i0natan did this get forgotten about? |
@whithajess This indeed got forgotten and it's about the perfect timing to bring back up! as we're now collecting performance best practices #256 Appreciate if you anyone who shared an idea here (@Ginden @gerardmrk @mscdex @snypelife @sebs) can also copy to #256 , I'll copy items that weren't copied by next week /remind me in a week |
@i0natan set a reminder for Oct 9th 2018 |
We should add a note on not blocking the Event loop (https://nodejs.org/en/docs/guides/dont-block-the-event-loop/) |
👋 @i0natan, |
@VinayaSathyanarayana Welcome! Can you add that to #256 ? /remind me next week |
@i0natan set a reminder for Oct 18th 2018 |
👋 @i0natan, |
I just got the reminder via email. Was that intended for me? I'm not sure if there's anything more I can contribute to this thread that hasn't been mentioned elsewhere or written better than I can articulate. If you'd like to post the stuff I've written, feel free to reword them as appropriate! |
@gerardmrk No, the reminder is for me to copy the items to the main performance ideas thread. Would you like to participate in writing as well? in any case, goes without saying that will reward you... :] |
Hello there! 👋 |
fix: spelling typo
I've written these simply (at work atm), so you'd have to reword them if you're going to add it to the README.
There is significant overhead when accessing environment variables during runtime, so avoid referencing
process.env
per HTTP request in your server code.Don't transpile your code in-memory at runtime (e.g. with transpilers like
babel-register
orts-node
), as they have to transpile everything and consume a lot of memory. Rather, pre-transpile your code before pushing to production.The text was updated successfully, but these errors were encountered: