FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fs: ES6 Spread Operator for extended parameter handling by mithunsasidharan · Pull Request #17486 · nodejs/node · GitHub

/ node Public

fs: ES6 Spread Operator for extended parameter handling - #17486

Closed
mithunsasidharan wants to merge 1 commit into
nodejs:masterfrom
mithunsasidharan:spread_operator
Closed

fs: ES6 Spread Operator for extended parameter handling#17486
mithunsasidharan wants to merge 1 commit into
nodejs:masterfrom
mithunsasidharan:spread_operator

Conversation

mithunsasidharan commented Dec 6, 2017
edited
Loading

Copy link
Copy Markdown
Contributor

Replaced f.apply(undefined, arguments) to ES 6 f(...arguments) Extended Parameter Handling Spread Operator in lib/fs.js

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

fs

nodejs-github-bot added the fs Issues and PRs related to the fs subsystem / file system. label Dec 6, 2017

Copy link
Copy Markdown
Member

These sort of changes need benchmarks - have you tried running the benchmarks and getting results?

apapirovski left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I'm sorry but I'm strongly -1 on this change. This will be much slower than using apply is.

Copy link
Copy Markdown
Contributor Author

@apapirovski : Thanks for the feedback. I'll close the PR.

Copy link
Copy Markdown
Member

@apapirovski would still love some benchmarks

Copy link
Copy Markdown
Contributor

@benjamingr I'm speaking from experience after trying to make this change on events and having the benchmarks be roughly 20-25% slower in certain situations. Theoretically this is supposed to be optimized (a basic benchmark shows maybe 2-3% perf gap and that might just be noise), practically there seem to be edge cases.

Copy link
Copy Markdown
Contributor Author

@apapirovski : Thanks for sharing that. Quite helpful 👍

Copy link
Copy Markdown
Member

@apapirovski can you send me a link to those benchmarks then? This is the third time we've been talking about whether or not spread is optimized or not and I want something concrete to go with when I bug V8 people about it :)

Copy link
Copy Markdown
Contributor

@benjamingr the benchmarks are just the events ones... I think I saw the issue when working on once or something similar. It's also possible it might've been in process.nextTick or timers. I can try to reproduce again when I have a moment.

Copy link
Copy Markdown
Contributor

I wish I had more info, it's just that I've been working on that stuff on-and-off for the past 2 months so it's a bit hard to recall at what point I encountered it. You could look over recent events, timers & process PRs potentially.

mithunsasidharan commented Dec 6, 2017
edited
Loading

Copy link
Copy Markdown
Contributor Author

@apapirovski @benjamingr : Just to mention, post closing the PR.. over my conversation with few JS experienced dev folks.. they did acknowledge too that f.apply(undefined, arguments); is much better performant than f(...arguments); in multiple different scenarios and they did confirm they've tested it !

Copy link
Copy Markdown
Contributor

ping @bmeurer any thoughts on fn(...arguments) vs fn.apply(undefined, arguments)? I'm almost certain I've run into edge cases before but I also know the V8 team has done work to optimize this recently?

apapirovski commented Dec 6, 2017
edited
Loading

Copy link
Copy Markdown
Contributor

FWIW I think the fastest combination here might be

function(...args) {
  return cb.apply(undefined, args);
}

When I test that version within once with ee-once benchmark, it's about 5% faster than using arguments. Don't ask me why...

@mithunsasidharan If you would like to try that version of the PR and run the relevant benchmarks in benchmark/fs then that PR could probably be accepted?

Here's the bench results after a short run:

fs/bench-readdir.js n=10000      1.95 %        *** 0.0006178907

Reasonably certain it's faster. Don't think it can land on v8.x or older though.

Copy link
Copy Markdown
Contributor

Also, you could potentially test fn(...args) { return cb(...args); }? It might be the same. Not sure.

Copy link
Copy Markdown
Contributor Author

@apapirovski : Can you take a look at updated change here ?

Comment thread lib/fs.js Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This should be ...args to match the variable below.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

@apapirovski : my bad.. will fix that !

Comment thread lib/fs.js Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

On that note, could we change this to Reflect.apply(cb, undefined, args);? Thank you! That will mean we no longer depend on the user provided apply.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

@apapirovski : Please take a look now. Thanks !

bmeurer commented Dec 6, 2017

Copy link
Copy Markdown
Member

@apapirovski Yes I also think fn.apply(undefined, args) is best for now.

apapirovski left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM if CI & benchmark CI are happy.

Copy link
Copy Markdown
Contributor

Copy link
Copy Markdown
Contributor Author

@apapirovski : Thanks much !

Copy link
Copy Markdown
Member

LGTM

apapirovski mentioned this pull request Dec 7, 2017
2 tasks

Copy link
Copy Markdown
Contributor

Landed in 0a0fbd5

apapirovski closed this Dec 8, 2017
apapirovski pushed a commit that referenced this pull request Dec 8, 2017
PR-URL: #17486
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Benedikt Meurer <benedikt.meurer@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
MylesBorins pushed a commit that referenced this pull request Dec 12, 2017
PR-URL: #17486
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Benedikt Meurer <benedikt.meurer@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
MylesBorins pushed a commit that referenced this pull request Dec 12, 2017
PR-URL: #17486
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Benedikt Meurer <benedikt.meurer@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
MylesBorins mentioned this pull request Dec 12, 2017
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fs Issues and PRs related to the fs subsystem / file system.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants


Back | FazBrowse Home | New Git URL