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

lib: refactor some lib/internals #11406

Closed
wants to merge 4 commits into from

Conversation

jasnell
Copy link
Member

@jasnell jasnell commented Feb 15, 2017

Some light refactoring of internals/*.js

  • For linkedlist and freelist, this yields about a 5% perf improvement in general
  • Consistent use of the module.exports = {} pattern, with module.exports = {} at the end.

(do not squash commits)

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines
Affected core subsystem(s)

lib/internal

@nodejs-github-bot nodejs-github-bot added the lib / src Issues and PRs related to general changes in the lib or src directory. label Feb 15, 2017

alloc() {
return this.list.length ? this.list.pop() :
this.constructor.apply(this, arguments);
Copy link
Contributor

Choose a reason for hiding this comment

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

Unrelated to this PR, but perhaps this can be simplified since http is the only user of FreeList and we'd know how what arguments to pass on to the constructor. I'm not sure if adding new would help (allowing us to avoid an instanceof check in the constructor if possible) more than it might hurt (e.g. if stack traces would change with new constructor(..)).

Copy link
Member Author

Choose a reason for hiding this comment

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

Worth playing around with. I would also note that I had attempted to replace this use of arguments with ...args, but found that in the case there are no arguments passed to the alloc(), it caused a whopping 48% slowdown. Definitely something we'll need to keep in mind.

@@ -11,8 +9,12 @@ function isLegalPort(port) {
return +port === (+port >>> 0) && port <= 0xFFFF;
}


Copy link
Contributor

Choose a reason for hiding this comment

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

Unintended?

class FreeList {
constructor(name, max, constructor) {
this.name = name;
this.constructor = constructor;
Copy link
Member

Choose a reason for hiding this comment

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

Naming own properties of instances constructor is kind of confusing, maybe you could change that while you’re here?

constructor(slave, key) {
super();
this.key = key;
this.slave = slave;
Copy link
Member

Choose a reason for hiding this comment

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

Likewise, it would be awesome if we could change this during the refactor (here and in the other parts of the file this PR touches).

@jasnell
Copy link
Member Author

jasnell commented Feb 16, 2017

@addaleax @mscdex ... updated!

@jasnell jasnell added the semver-major PRs that contain breaking changes and should be released in the next major version. label Feb 16, 2017
@jasnell
Copy link
Member Author

jasnell commented Feb 16, 2017

semver-major because an error message is changed.

@jasnell
Copy link
Member Author

jasnell commented Feb 19, 2017

jasnell added a commit that referenced this pull request Feb 22, 2017
PR-URL: #11406
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
jasnell added a commit that referenced this pull request Feb 22, 2017
PR-URL: #11406
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
jasnell added a commit that referenced this pull request Feb 22, 2017
PR-URL: #11406
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
jasnell added a commit that referenced this pull request Feb 22, 2017
Switch to using the more efficient module.exports = {}
where possible.

PR-URL: #11406
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
@jasnell
Copy link
Member Author

jasnell commented Feb 22, 2017

Landed in d61a511...62e9609

@jasnell jasnell closed this Feb 22, 2017
@jasnell jasnell mentioned this pull request Apr 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lib / src Issues and PRs related to general changes in the lib or src directory. semver-major PRs that contain breaking changes and should be released in the next major version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants