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: construct Buffers in JS by trevnorris · Pull Request #2866 · nodejs/node

Conversation

@trevnorris

@trevnorris trevnorris commented Sep 14, 2015

Copy link
Copy Markdown
Contributor

Overall construction time is faster in JS, but the problem is zero-fill
of memory. Get around this by using a flag in the ArrayBuffer::Allocator
to trigger when memory should or shouldn't be zero-filled.

R=@bnoordhuis
R=@indutny

Warning. There is some mess in here. Throwing it up for general review.

Sorry, something went wrong.

Uh oh!

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

All reactions
indutny
indutny reviewed Sep 14, 2015
View reviewed changes
Comment thread lib/buffer.js

@indutny indutny Sep 14, 2015

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.

What do you think about making this one-byte Uint8Array instead, and passing it to the C++?

Sorry, something went wrong.

Uh oh!

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

All reactions

@indutny indutny Sep 14, 2015

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.

nvm, you did it this way :)

Sorry, something went wrong.

Uh oh!

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

All reactions
@brendanashworth brendanashworth added the buffer Issues and PRs related to the buffer subsystem. label Sep 14, 2015
@trevnorris
trevnorris force-pushed the avoid-zero-fill branch from ff32546 to feee1d4 Compare September 14, 2015 23:13
indutny
indutny reviewed Sep 15, 2015
View reviewed changes
Comment thread lib/buffer.js Outdated

@indutny indutny Sep 15, 2015

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.

What do you think about getting rid of this thing and using class.. extends?

Sorry, something went wrong.

Uh oh!

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

All reactions

@trevnorris trevnorris Sep 15, 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.

super() cannot be optimized. using class.. extends was the first approach I took when reimplementing Buffer and it had significant overhead. Which is the initial reason I went the route of the C++ construction.

Sorry, something went wrong.

Uh oh!

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

All reactions
@trevnorris
trevnorris force-pushed the avoid-zero-fill branch from feee1d4 to 6dbb278 Compare September 15, 2015 18:16
@trevnorris
buffer: construct Uint8Array in JS
d235fe2
Overall construction time of Typed Arrays is faster in JS, but the
problem with using it normally is zero-fill of memory. Get around this
by using a flag in the ArrayBuffer::Allocator to trigger when memory
should or shouldn't be zero-filled.

Remove Buffer::Create() as it is no longer called.

The creation of the Uint8Array() was done at each callsite because at
the time of this patch there was a performance penalty for centralizing
the call in a single function.
@trevnorris
trevnorris force-pushed the avoid-zero-fill branch from 6dbb278 to d235fe2 Compare September 15, 2015 18:27
indutny
indutny reviewed Sep 15, 2015
View reviewed changes
Comment thread lib/buffer.js

@indutny indutny Sep 15, 2015

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.

Hahaha, this one is better! :)

Are you afraid of class...extends? We can address it later, though.

Sorry, something went wrong.

Uh oh!

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

All reactions

@trevnorris trevnorris Sep 15, 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.

class is too slow. The call to super() can't be optimized by v8. I learned this b/c the initial implementation used class...extends and I never saw the constructor show up in IRHydra.

Sorry, something went wrong.

Uh oh!

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

All reactions

@indutny indutny Sep 15, 2015

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.

You sure about this? I have seen the disassembly output, and it looked like the Buffer constructor was inlined and was called Uint8Array constructor directly

Sorry, something went wrong.

Uh oh!

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

All reactions

@trevnorris trevnorris Sep 15, 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.

This was when class was very first supported. So additional optimizations may have been done since then.

Sorry, something went wrong.

Uh oh!

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

All reactions
@indutny

indutny commented Sep 15, 2015

Copy link
Copy Markdown
Member

One naming nit, otherwise LGTM.

All reactions

Sorry, something went wrong.

Uh oh!

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

trevnorris added a commit that referenced this pull request Sep 15, 2015
@trevnorris
buffer: construct Uint8Array in JS
74178a5
Overall construction time of Typed Arrays is faster in JS, but the
problem with using it normally is zero-fill of memory. Get around this
by using a flag in the ArrayBuffer::Allocator to trigger when memory
should or shouldn't be zero-filled.

Remove Buffer::Create() as it is no longer called.

The creation of the Uint8Array() was done at each callsite because at
the time of this patch there was a performance penalty for centralizing
the call in a single function.

PR-URL: #2866
Reviewed-By: Fedor Indutny <[email protected]>
@trevnorris

trevnorris commented Sep 15, 2015

Copy link
Copy Markdown
Contributor Author

Suggested name changed. Landed in 74178a5.

All reactions

Sorry, something went wrong.

Uh oh!

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

@trevnorris trevnorris closed this Sep 15, 2015
@trevnorris trevnorris added the land-on-v4.x label Sep 15, 2015
@trevnorris
trevnorris deleted the avoid-zero-fill branch September 15, 2015 22:28
trevnorris added a commit that referenced this pull request Sep 16, 2015
@trevnorris @Fishrock123
buffer: construct Uint8Array in JS
7df018a
Overall construction time of Typed Arrays is faster in JS, but the
problem with using it normally is zero-fill of memory. Get around this
by using a flag in the ArrayBuffer::Allocator to trigger when memory
should or shouldn't be zero-filled.

Remove Buffer::Create() as it is no longer called.

The creation of the Uint8Array() was done at each callsite because at
the time of this patch there was a performance penalty for centralizing
the call in a single function.

PR-URL: #2866
Reviewed-By: Fedor Indutny <[email protected]>
@Fishrock123 Fishrock123 mentioned this pull request Sep 16, 2015
Release proposal: v4.1.0 #2844
Closed
3 of 7 tasks
Fishrock123 added a commit to Fishrock123/node that referenced this pull request Sep 17, 2015
@Fishrock123
2015-09-17, Version 4.1.0 (Stable) Release
b4ec2c2
Notable changes:

* buffer:
  - Buffers are now created in JavaScript, rather than C++. This increases the speed of buffer creation (Trevor Norris) nodejs#2866.
  - `Buffer#slice()` now uses `Uint8Array#subarray()` internally, increasing `slice()` performance (Karl Skomski) nodejs#2777.
* fs:
  - `fs.utimes()` now properly converts numeric strings, `NaN`, and `Infinity` (Yazhong Liu) nodejs#2387.
  - `fs.WriteStream` now implements `_writev`, allowing for super-fast bulk writes (Ron Korving) nodejs#2167.
* http: Fixed an issue with certain `write()` sizes causing errors when using `http.request()` (Fedor Indutny) nodejs#2824.
* npm: Upgrade to version 2.14.3, see https://github.com/npm/npm/releases/tag/v2.14.3 for more details (Kat Marchán) nodejs#2822.
* src: V8 cpu profiling no longer erroneously shows idle time (Oleksandr Chekhovskyi) nodejs#2324.
* v8: Lateral upgrade to 4.5.103.33 from 4.5.103.30, contains minor fixes (Ali Ijaz Sheikh) nodejs#2870.
  - This fixes a previously known bug where some computed object shorthand properties did not work correctly (nodejs#2507).

Refs: nodejs#2844
PR-URL: nodejs#2889
Fishrock123 added a commit that referenced this pull request Sep 17, 2015
@Fishrock123 @rvagg
2015-09-17, Version 4.1.0 (Stable) Release
e4f2952
Notable changes:

* buffer:
  - Buffers are now created in JavaScript, rather than C++. This increases the speed of buffer creation (Trevor Norris) #2866.
  - `Buffer#slice()` now uses `Uint8Array#subarray()` internally, increasing `slice()` performance (Karl Skomski) #2777.
* fs:
  - `fs.utimes()` now properly converts numeric strings, `NaN`, and `Infinity` (Yazhong Liu) #2387.
  - `fs.WriteStream` now implements `_writev`, allowing for super-fast bulk writes (Ron Korving) #2167.
* http: Fixed an issue with certain `write()` sizes causing errors when using `http.request()` (Fedor Indutny) #2824.
* npm: Upgrade to version 2.14.3, see https://github.com/npm/npm/releases/tag/v2.14.3 for more details (Kat Marchán) #2822.
* src: V8 cpu profiling no longer erroneously shows idle time (Oleksandr Chekhovskyi) #2324.
* v8: Lateral upgrade to 4.5.103.33 from 4.5.103.30, contains minor fixes (Ali Ijaz Sheikh) #2870.
  - This fixes a previously known bug where some computed object shorthand properties did not work correctly (#2507).

Refs: #2844
PR-URL: #2889
@rvagg rvagg mentioned this pull request Sep 22, 2015
Release proposal: v4.1.1 #2995
Merged
@jasnell jasnell added the lts-landed-on-v4.x label Oct 7, 2015
@MylesBorins

MylesBorins commented Nov 16, 2015

Copy link
Copy Markdown
Contributor

landed in lts-v4.x-staging as 7df018a

All reactions

Sorry, something went wrong.

Uh oh!

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

@MylesBorins MylesBorins removed the land-on-v4.x label Nov 16, 2015
@ronag ronag mentioned this pull request Jul 14, 2019
stream: always invoke end callback #28687
Closed
4 tasks done
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.

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.

5 participants

@trevnorris @indutny @MylesBorins @jasnell @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.