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

path: refactor for performance and consistency by nwoltman · Pull Request #1778 · nodejs/node · GitHub

/ node Public

path: refactor for performance and consistency - #1778

Closed
nwoltman wants to merge 2 commits into
nodejs:masterfrom
nwoltman:path
Closed

path: refactor for performance and consistency#1778
nwoltman wants to merge 2 commits into
nodejs:masterfrom
nwoltman:path

Conversation

Copy link
Copy Markdown
Contributor

Convergence PR prompted by #35
Original PR: nodejs/node-v0.x-archive#9289

Original PR message (slightly modified):


Improve performance by:

  • Not leaking the arguments object in win32.join
  • Getting the last character of a string by index, instead of with .substr() or .slice()

Improve code consistency by:

  • Using [] instead of .charAt() where possible
  • Using a function declaration instead of a var declaration
  • Using .slice() with clearer arguments

Improve both by:

  • Making the reusable trimArray() function
  • Standardizing getting certain path statistics with the new win32StatPath() function

Benchmarks: (higher is better)

function (path.) current (ops/sec) this PR (ops/sec)
win32.resolve 315,019 399,543
win32.normalize 873,559 1,051,170
win32.isAbsolute 1,915,332 1,939,849
win32.join 452,879 815,033
win32.relative 153,821 219,928
win32.format 13,118,588 16,364,384
posix.relative 244,638 304,456
Benchmark code (gist)

mscdex added the path Issues and PRs related to the path subsystem. label May 23, 2015
Comment thread lib/path.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

First letter should be capitalized.

Copy link
Copy Markdown
Contributor

Are there any API changes? (seeing that the tests were modified)

Copy link
Copy Markdown
Contributor Author

@silverwind I'm not sure if this counts as an API change, but as discussed here, if a user passes in an object where the dir property is null or undefined, these changes make it so that the function returns the correct value instead of incorrectly throwing.

Copy link
Copy Markdown
Member

I'm keen on getting the benchmark in (benchmarks/fs/) as well – but we haven't started using benchmark.js just quite yet. If you're keen, rewriting it slightly would be nice.

Copy link
Copy Markdown
Contributor Author

@jbergstroem It looks like each path method would require it's own benchmark file. That's going to be a fair number of files so perhaps they should go in a new benchmark/path directory?
Then there's the question of whether or not the path.win32 and path.posix methods should be in their own files, or if they should be compared in the same file (similar to the Buffer/SlowBuffer comparison).

ChALkeR commented May 23, 2015

Copy link
Copy Markdown
Member

Looks like #1752 conflicts with this. I will remove the path.win32 part from #1752 once this gets merged.

Btw,

In path.win32.join this PR changes the stack of the TypeError('Arguments to path.join must be strings'), removing the top at f (path.js:190:13) and at Object.filter (native) so now it is similar to the stack in path.posix.join.

Is also valid for this PR.

jasnell commented May 27, 2015

Copy link
Copy Markdown
Member

LGTM

ChALkeR commented May 27, 2015

Copy link
Copy Markdown
Member

Why using slice instead of substr/substring for strings?

Copy link
Copy Markdown
Contributor Author

@ChALkeR I haven't changed any code to use slice instead of substr/substring. If you're specifically referring to this line, yes I could have changed slice to substr, but instead I changed the input value to make the code cleaner and easier to read.

nwoltman commented Jun 6, 2015

Copy link
Copy Markdown
Contributor Author

@jbergstroem I added some benchmarks. Do those look about right?

Copy link
Copy Markdown
Member

@woollybogger apologies for the late reply. LGTM. CI here: https://jenkins-iojs.nodesource.com/job/iojs+any-pr+multi/827/

Copy link
Copy Markdown
Contributor Author

@jbergstroem A couple unrelated (and possibly flaky) tests failed. Does that matter?

Copy link
Copy Markdown
Member

@woollybogger no, that's something we're working on improving. I can't access the old results -- can you rebase on top of latest master so we can get a new run going?

You might want to see if anyone else wants to review before I/someone else look at landing it. @ChALkeR?

Copy link
Copy Markdown
Contributor Author

Rebased

Copy link
Copy Markdown
Member

Copy link
Copy Markdown
Member

(never mind the windows timeouts)

ChALkeR commented Jun 17, 2015

Copy link
Copy Markdown
Member

The main part (lib/path.js) LGTM.

Minor thing: you replace single-char .substr() and .charAt() with [] in all places of path module, but this one:

posix.isAbsolute = function(path) {
  assertPath(path);
  return path.charAt(0) === '/';
};

Could you fix that for consistency?

Copy link
Copy Markdown
Contributor Author

@ChALkeR Fixed.

Comment thread lib/path.js

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 am not sure if returning the original array and a new array based on conditions is a good idea.

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

It's just a little helper function. There's no point in making a copy of an array when the original is all you need.

Copy link
Copy Markdown
Contributor Author

bump 🚅

brendanashworth added the benchmark Issues and PRs related to the benchmark subsystem. label Jun 26, 2015
Comment thread lib/path.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

Could use shorthand properties here:

return {
  device,
  isUnc,
  isAbsolute: isUnc || !!result[2], // UNC paths are always absolute
  tail: result[3]
};

Copy link
Copy Markdown
Contributor

LGTM, few nits and a question above.

Improve performance by:
+ Not leaking the `arguments` object!
+ Getting the last character of a string by index, instead of
  with `.substr()` or `.slice()`

Improve code consistency by:
+ Using `[]` instead of `.charAt()` where possible
+ Using a function declaration instead of a var declaration
+ Using `.slice()` with clearer arguments
+ Checking if `dir` is truthy in `win32.format`
  (added tests for this)

Improve both by:
+ Making the reusable `trimArray()` function
+ Standardizing getting certain path statistics with
  the new `win32StatPath()` function
Path functions being benchmarked are:
* format
* isAbsolute
* join
* normalize
* relative
* resolve

nwoltman commented Jul 3, 2015

Copy link
Copy Markdown
Contributor Author

Updated

Copy link
Copy Markdown
Contributor

LGTM

silverwind pushed a commit that referenced this pull request Jul 4, 2015
Improve performance by:
+ Not leaking the `arguments` object!
+ Getting the last character of a string by index, instead of
  with `.substr()` or `.slice()`

Improve code consistency by:
+ Using `[]` instead of `.charAt()` where possible
+ Using a function declaration instead of a var declaration
+ Using `.slice()` with clearer arguments
+ Checking if `dir` is truthy in `win32.format`
  (added tests for this)

Improve both by:
+ Making the reusable `trimArray()` function
+ Standardizing getting certain path statistics with
  the new `win32StatPath()` function

PR-URL: #1778
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
silverwind pushed a commit that referenced this pull request Jul 4, 2015
Path functions being benchmarked are:
* format
* isAbsolute
* join
* normalize
* relative
* resolve

PR-URL: #1778
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>

Copy link
Copy Markdown
Contributor

Landed in bca53dc and 0d15161

silverwind closed this Jul 4, 2015
nwoltman deleted the path branch July 8, 2015 03:36
mscdex pushed a commit to mscdex/io.js that referenced this pull request Jul 9, 2015
Improve performance by:
+ Not leaking the `arguments` object!
+ Getting the last character of a string by index, instead of
  with `.substr()` or `.slice()`

Improve code consistency by:
+ Using `[]` instead of `.charAt()` where possible
+ Using a function declaration instead of a var declaration
+ Using `.slice()` with clearer arguments
+ Checking if `dir` is truthy in `win32.format`
  (added tests for this)

Improve both by:
+ Making the reusable `trimArray()` function
+ Standardizing getting certain path statistics with
  the new `win32StatPath()` function

PR-URL: nodejs#1778
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
mscdex pushed a commit to mscdex/io.js that referenced this pull request Jul 9, 2015
Path functions being benchmarked are:
* format
* isAbsolute
* join
* normalize
* relative
* resolve

PR-URL: nodejs#1778
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
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

benchmark Issues and PRs related to the benchmark subsystem. path Issues and PRs related to the path subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants


Back | FazBrowse Home | New Git URL