GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — path: refactor for performance and consistency by nwoltman · Pull Request #1778 · nodejs/node

Conversation

@nwoltman

@nwoltman nwoltman commented May 23, 2015

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)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@mscdex mscdex added the path Issues and PRs related to the path subsystem. label May 23, 2015
mscdex
mscdex reviewed May 23, 2015
View reviewed changes
Comment thread lib/path.js Outdated

@mscdex mscdex May 23, 2015

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

First letter should be capitalized.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@silverwind

silverwind commented May 23, 2015

Copy link
Copy Markdown
Contributor

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nwoltman

nwoltman commented May 23, 2015

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jbergstroem

jbergstroem commented May 23, 2015

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nwoltman

nwoltman commented May 23, 2015

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).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ChALkeR

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jasnell

jasnell commented May 27, 2015

Copy link
Copy Markdown
Member

LGTM

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ChALkeR

ChALkeR commented May 27, 2015

Copy link
Copy Markdown
Member

Why using slice instead of substr/substring for strings?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jasnell jasnell mentioned this pull request May 27, 2015
[Converge] path: refactor for performance and consistency nodejs/node-convergence-archive#35
Closed
@nwoltman

nwoltman commented May 27, 2015

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bnoordhuis
bnoordhuis force-pushed the master branch from 311c3e4 to b926718 Compare June 2, 2015 17:25
@nwoltman

nwoltman commented Jun 6, 2015

Copy link
Copy Markdown
Contributor Author

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jbergstroem

jbergstroem commented Jun 13, 2015

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/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nwoltman

nwoltman commented Jun 16, 2015

Copy link
Copy Markdown
Contributor Author

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jbergstroem

jbergstroem commented Jun 16, 2015

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?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nwoltman

nwoltman commented Jun 16, 2015

Copy link
Copy Markdown
Contributor Author

Rebased

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jbergstroem

jbergstroem commented Jun 16, 2015

Copy link
Copy Markdown
Member

CI here: https://jenkins-iojs.nodesource.com/job/iojs+any-pr+multi/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jbergstroem

jbergstroem commented Jun 16, 2015

Copy link
Copy Markdown
Member

(never mind the windows timeouts)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ChALkeR

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?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nwoltman

nwoltman commented Jun 17, 2015

Copy link
Copy Markdown
Contributor Author

@ChALkeR Fixed.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

thefourtheye
thefourtheye reviewed Jun 17, 2015
View reviewed changes
Comment thread lib/path.js

@thefourtheye thefourtheye Jun 17, 2015

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I am not sure if returning the original array and a new array based on conditions is a good idea.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@nwoltman nwoltman Jun 17, 2015

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@rvagg
rvagg force-pushed the master branch from 9d21135 to 628a3ab Compare June 25, 2015 09:18
@nwoltman

nwoltman commented Jun 26, 2015

Copy link
Copy Markdown
Contributor Author

bump 🚅

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@brendanashworth brendanashworth added the benchmark Issues and PRs related to Node.js benchmarks and benchmarking infrastructure. label Jun 26, 2015
silverwind
silverwind reviewed Jul 3, 2015
View reviewed changes
Comment thread lib/path.js Outdated

@silverwind silverwind Jul 3, 2015

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Could use shorthand properties here:

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@silverwind

silverwind commented Jul 3, 2015

Copy link
Copy Markdown
Contributor

LGTM, few nits and a question above.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nwoltman
path: refactor for performance and consistency
84e4f5b
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
@nwoltman
benchmark: Add some path benchmarks for #1778
363335c
Path functions being benchmarked are:
* format
* isAbsolute
* join
* normalize
* relative
* resolve
@nwoltman

nwoltman commented Jul 3, 2015

Copy link
Copy Markdown
Contributor Author

Updated

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@silverwind

silverwind commented Jul 3, 2015

Copy link
Copy Markdown
Contributor

LGTM

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

silverwind pushed a commit that referenced this pull request Jul 4, 2015
@nwoltman @silverwind
path: refactor for performance and consistency
bca53dc
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: Сковорода Никита Андреевич <[email protected]>
Reviewed-By: Roman Reiss <[email protected]>
silverwind pushed a commit that referenced this pull request Jul 4, 2015
@nwoltman @silverwind
benchmark: Add some path benchmarks for #1778
0d15161
Path functions being benchmarked are:
* format
* isAbsolute
* join
* normalize
* relative
* resolve

PR-URL: #1778
Reviewed-By: Сковорода Никита Андреевич <[email protected]>
Reviewed-By: Roman Reiss <[email protected]>
@silverwind

silverwind commented Jul 4, 2015

Copy link
Copy Markdown
Contributor

Landed in bca53dc and 0d15161

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@silverwind silverwind closed this Jul 4, 2015
@Fishrock123 Fishrock123 mentioned this pull request Jul 6, 2015
Release proposal: v2.3.4 #2115
Merged
@nwoltman
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
@nwoltman @mscdex
path: refactor for performance and consistency
3b2da61
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: Сковорода Никита Андреевич <[email protected]>
Reviewed-By: Roman Reiss <[email protected]>
mscdex pushed a commit to mscdex/io.js that referenced this pull request Jul 9, 2015
@nwoltman @mscdex
benchmark: Add some path benchmarks for nodejs#1778
9d58f77
Path functions being benchmarked are:
* format
* isAbsolute
* join
* normalize
* relative
* resolve

PR-URL: nodejs#1778
Reviewed-By: Сковорода Никита Андреевич <[email protected]>
Reviewed-By: Roman Reiss <[email protected]>
@snyk-bot snyk-bot mentioned this pull request Apr 2, 2021
[Snyk] Security upgrade snyk from 1.437.3 to 1.518.0 turkdevops/node#241
Closed
@snyk-bot snyk-bot mentioned this pull request Aug 24, 2021
[Snyk] Security upgrade snyk from 1.437.3 to 1.518.0 turkdevops/node#317
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

benchmark Issues and PRs related to Node.js benchmarks and benchmarking infrastructure. path Issues and PRs related to the path subsystem.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

8 participants

@nwoltman @silverwind @jbergstroem @ChALkeR @jasnell @mscdex @thefourtheye @brendanashworth
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.