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 — buffer: faster case for create buffer from empty string by JacksonTian · Pull Request #4414 · nodejs/node

Conversation

@JacksonTian

@JacksonTian JacksonTian commented Dec 24, 2015

Copy link
Copy Markdown
Contributor

When create Buffer from empty string will touch
C++ binding also.

This patch can improve edge case ~70% faster.
following is benchmark results.

Sorry, something went wrong.

Uh oh!

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

All reactions
@mscdex

mscdex commented Dec 24, 2015

Copy link
Copy Markdown
Contributor

I'm confused, so it got slower after this patch? It went from 2767 ops/sec to 605 ops/sec and 2599 ops/sec to 1249 ops/sec?

All reactions

Sorry, something went wrong.

Uh oh!

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

@mscdex mscdex added the buffer Issues and PRs related to the buffer subsystem. label Dec 24, 2015
@JacksonTian
JacksonTian force-pushed the edge branch from 1bdb82e to 70a617c Compare December 24, 2015 09:49
@JacksonTian

JacksonTian commented Dec 24, 2015

Copy link
Copy Markdown
Contributor Author

@mscdex I updated the results. the buffer result is noisy because I used old version(not lastest version) to run it.

All reactions

Sorry, something went wrong.

Uh oh!

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

@jasnell jasnell added the lts-watch-v4.x label Dec 25, 2015
@jbergstroem

jbergstroem commented Dec 26, 2015

Copy link
Copy Markdown
Member

CI: https://ci.nodejs.org/job/node-test-commit/1533/

All reactions

Sorry, something went wrong.

Uh oh!

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

@Trott
Trott force-pushed the master branch from 1e896a6 to 082cc8d Compare December 27, 2015 02:01
trevnorris
trevnorris reviewed Dec 28, 2015
View reviewed changes
Comment thread lib/buffer.js Outdated

@trevnorris trevnorris Dec 28, 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.

new is unnecessary anymore since it forces a return of a new Uint8Array.

Sorry, something went wrong.

Uh oh!

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

All reactions

@silverwind silverwind Jan 11, 2016

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.

@JacksonTian can you address this?

Sorry, something went wrong.

Uh oh!

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

All reactions

@JacksonTian JacksonTian Jan 11, 2016

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.

I prefer use new with constructor.

Sorry, something went wrong.

Uh oh!

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

All reactions

@silverwind silverwind Jan 11, 2016

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 do, too. I think there's even a linter rule in place for it. Are you fine with it @trevnorris?

Sorry, something went wrong.

Uh oh!

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

All reactions

@trevnorris trevnorris Jan 11, 2016

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.

@silverwind The code works fine, but we're allocating an unnecessary object. Though I doubt that has an impact on performance either. Part of the point is that Buffer is not an actual constructor anymore. It's now more of a factory method. But again it's nothing serious or is a change that needs to be made.

Sorry, something went wrong.

Uh oh!

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

All reactions
@trevnorris

trevnorris commented Dec 28, 2015

Copy link
Copy Markdown
Contributor

One comment but LGTM.

All reactions

Sorry, something went wrong.

Uh oh!

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

@JacksonTian
JacksonTian force-pushed the edge branch from 70a617c to faf8339 Compare December 31, 2015 10:05
@jasnell

jasnell commented Jan 15, 2016

Copy link
Copy Markdown
Member

New CI, the last one appears to have died completely: https://ci.nodejs.org/job/node-test-pull-request/1246/

All reactions

Sorry, something went wrong.

Uh oh!

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

@ChALkeR ChALkeR added the performance Issues and PRs related to the performance of Node.js. label Feb 16, 2016
@jasnell

jasnell commented Mar 22, 2016

Copy link
Copy Markdown
Member

@JacksonTian ... can you rebase this and update the new Buffer() usage to use the new constructor APIs (Buffer.alloc(0))

All reactions

Sorry, something went wrong.

Uh oh!

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

@JacksonTian

JacksonTian commented Mar 23, 2016

Copy link
Copy Markdown
Contributor Author

Hi, @jasnell , the branch rebased.

./node benchmark/compare.js ./node ~/git/node/node -- buffers buffer_zero
running ./node
buffers/buffer_zero.js
running /Users/jacksontian/git/node/node
buffers/buffer_zero.js

buffers/buffer_zero.js n=1024 type=buffer: ./node: 1824.6 /Users/jacksontian/git/node/node: 1842.9 . -0.99%
buffers/buffer_zero.js n=1024 type=string: ./node: 1901.3 /Users/jacksontian/git/node/node: 956.59 . 98.76%
All reactions

Sorry, something went wrong.

Uh oh!

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

@JacksonTian
JacksonTian force-pushed the edge branch 2 times, most recently from 514aa5a to 03579ba Compare March 23, 2016 13:27
bnoordhuis
bnoordhuis reviewed Mar 23, 2016
View reviewed changes
Comment thread benchmark/buffers/buffer_zero.js Outdated

@bnoordhuis bnoordhuis Mar 23, 2016

Copy link
Copy Markdown
Member

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.

The change to lib/buffer.js LGTM but I wonder if it makes a difference on the benchmark numbers when you hoist out the conditional like this:

if (conf.type === 'buffer')
  for (let i = 0; i < n * 1024; i++) Buffer.from(zeroBuffer);
else if (conf.type === 'string')
  for (let i = 0; i < n * 1024; i++) Buffer.from(zeroString);

Also, I'm not sure if crankshaft will constant-fold the expression n * 1024 away, you might want to check if caching it makes a difference.

Sorry, something went wrong.

Uh oh!

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

All reactions

@JacksonTian JacksonTian Mar 23, 2016

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.

I think it's unrelated. these code is running in difference process when benchmarking it.

Sorry, something went wrong.

Uh oh!

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

All reactions

@bnoordhuis bnoordhuis Mar 23, 2016

Copy link
Copy Markdown
Member

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.

Sorry if I'm being unclear. What I mean is that the overhead of the check and the multiplication may affect the benchmark results. They probably don't but it would be good to check.

Sorry, something went wrong.

Uh oh!

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

All reactions

@JacksonTian JacksonTian Mar 23, 2016

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.

You mean the conf.type === 'buffer' will be run much times?

在 2016年3月23日,下午9:53,Ben Noordhuis <[email protected] mailto:[email protected]> 写道:

In benchmark/buffers/buffer_zero.js #4414 (comment):

function main(conf) {
var n = +conf.n;
bench.start();
for (let i = 0; i < n * 1024; i++) {

  • Buffer.from(zero);
  • conf.type === 'buffer' ? Buffer.from(zeroBuffer) : Buffer.from(zeroString);
    Sorry if I'm being unclear. What I mean is that the overhead of the check and the multiplication may affect the benchmark results. They probably don't but it would be good to check.

—
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub https://github.com/nodejs/node/pull/4414/files/03579ba47a711923c67215d63385b60cdf473c98#r57161722

Sorry, something went wrong.

Uh oh!

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

All reactions
@JacksonTian
buffer: faster case for create buffer from empty string
de8f36d
When create Buffer from empty string will touch
C++ binding also.

This patch can improve edge case ~70% faster.
@JacksonTian
JacksonTian force-pushed the edge branch from 03579ba to de8f36d Compare March 23, 2016 14:48
@JacksonTian

JacksonTian commented Mar 23, 2016

Copy link
Copy Markdown
Contributor Author

Hi, @bnoordhuis I update the benchmark script. following is result:

./node
buffers/buffer_zero.js
running /Users/jacksontian/git/node/node
buffers/buffer_zero.js

buffers/buffer_zero.js n=1024 type=buffer: ./node: 2019.3 /Users/jacksontian/git/node/node: 2039.4 . -0.99%
buffers/buffer_zero.js n=1024 type=string: ./node: 1935.6 /Users/jacksontian/git/node/node: 1136.6 . 70.29%
All reactions

Sorry, something went wrong.

Uh oh!

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

@jasnell

jasnell commented Mar 23, 2016

Copy link
Copy Markdown
Member

LGTM if @bnoordhuis is happy and CI is green

All reactions

Sorry, something went wrong.

Uh oh!

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

@jasnell

jasnell commented Mar 23, 2016

Copy link
Copy Markdown
Member

New CI: https://ci.nodejs.org/job/node-test-pull-request/2042/

All reactions

Sorry, something went wrong.

Uh oh!

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

jasnell pushed a commit that referenced this pull request Mar 27, 2016
@JacksonTian @jasnell
buffer: faster case for create buffer from empty string
afd821a
When create Buffer from empty string will touch
C++ binding also.

This patch can improve edge case ~70% faster.

PR-URL: #4414
Reviewed-By: Trevor Norris <[email protected]>
Reviewed-By: James M Snell <[email protected]>
@jasnell

jasnell commented Mar 27, 2016

Copy link
Copy Markdown
Member

CI was green. Landed in afd821a

All reactions

Sorry, something went wrong.

Uh oh!

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

@jasnell jasnell closed this Mar 27, 2016
evanlucas pushed a commit that referenced this pull request Mar 30, 2016
@JacksonTian @evanlucas
buffer: faster case for create buffer from empty string
18db2af
When create Buffer from empty string will touch
C++ binding also.

This patch can improve edge case ~70% faster.

PR-URL: #4414
Reviewed-By: Trevor Norris <[email protected]>
Reviewed-By: James M Snell <[email protected]>
@evanlucas evanlucas mentioned this pull request Mar 31, 2016
v5.10.0 Release Proposal #5970
Closed
@evanlucas

evanlucas commented Mar 31, 2016

Copy link
Copy Markdown
Contributor

Hm, it looks like this is failing on v5.x right now.

Apparently, the following no longer throws an error:

Buffer('', 'buffer')
All reactions

Sorry, something went wrong.

Uh oh!

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

@evanlucas

evanlucas commented Mar 31, 2016

Copy link
Copy Markdown
Contributor

It looks like master has https://github.com/nodejs/node/blame/master/lib/buffer.js#L211 and v5.x does not.

I'm not sure if that was intentional or not, but I'm a little weary of including this in v5.x for now. I'm going to leave it out of v5.10.0 and we can reevaluate

All reactions

Sorry, something went wrong.

Uh oh!

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

@evanlucas evanlucas added the dont-land-on-v5.x label Mar 31, 2016
@jasnell

jasnell commented Mar 31, 2016

Copy link
Copy Markdown
Member

Given that the change was an additional throw (and therefore semver major),
it was intentionally left out of the backport to v5.
On Mar 31, 2016 7:38 AM, "Evan Lucas" [email protected] wrote:

It looks like master has
https://github.com/nodejs/node/blame/master/lib/buffer.js#L211 and v5.x
does not.

I'm not sure if that was intentional or not, but I'm a little weary of
including this in v5.x for now. I'm going to leave it out of v5.10.0 and we
can reevaluate

—
You are receiving this because you modified the open/close state.
Reply to this email directly or view it on GitHub
#4414 (comment)

All reactions

Sorry, something went wrong.

Uh oh!

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

@evanlucas

evanlucas commented Mar 31, 2016

Copy link
Copy Markdown
Contributor

Sounds good to me. Thanks!

All reactions

Sorry, something went wrong.

Uh oh!

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

@MylesBorins MylesBorins added dont-land-on-v4.x and removed lts-watch-v4.x labels Apr 8, 2016
@theanarkh theanarkh mentioned this pull request Aug 17, 2022
[v18.x backport] lib: add diagnostics channel and perf hooks detail #44256
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

buffer Issues and PRs related to the buffer subsystem. performance Issues and PRs related to the performance of Node.js.

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.

10 participants

@JacksonTian @mscdex @jbergstroem @trevnorris @jasnell @evanlucas @silverwind @bnoordhuis @ChALkeR @MylesBorins
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 01402503 — 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.