-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
perf(pg): avoid useless spread #3379
Conversation
👍 🙇 |
The spread was intentional. Did you benchmark this? |
Yep! but the difference is negligible. In multiple run, sometimes wins the spread version, but I think is just because we talking about a very little difference. Honestly I have read the comment but not fully undestand why the spread should be improve the performance, it create a new object! Maybe @koenfaro90 can help us @charmander do you have noticed some slow down in the latest version? |
Constructing using spread itself is not any faster or slower. But USING objects generated with a 'fixed' shape is MUCH MUCH faster than using objects which are dynamically shaped. So if you start with an object with 0 properties and continually add properties the shape of that object will be complex - versus assigning all of them at initialization which leads to a simple shape. Some more background at https://v8.dev/blog/fast-properties The patch I made ensured that objects have a 'simple' shape. This results in significant (IIRC 10-100x) speed-up when doing something like JSON.stringify on the returned objects - considering the objects contain a significant amount of columns. |
Thanks for the detailed response! In your opinion my changes https://github.com/brianc/node-postgres/pull/3379/files can be a problem? |
Yes; this removes the performance fix as now you are using a dynamically shaped object to clone from, resulting in a major performance regression for any application using this library. So in my opinion this should be reverted before the next release. Perhaps we should add some tests regarding the performance of using the objects resulting from PG? I have a repo running some tests: https://github.com/koenfaro90/node-postgres-bench/tree/master |
ok, I have understood, thanks. Sorry for my mistake! With this PR #3382 revert both in |
* Update result.js * Update build-result.js * fix: lint * fix: lint
Perhaps add some comments to explain the reason why these spreads are necessary. |
@koenfaro90 version 8.13.2 (the version with my PR) has introduced slowness compared to 8.13.1
Side note, this project is gold https://github.com/koenfaro90/node-postgres-bench/tree/master and should be part of this repo! |
Just a micro-optimization for avoid useless spread operator on object