GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||
GeezerVison is showing github.com — buffer: implement `iterable` interface by vkurchatkin · Pull Request #204 · nodejs/node Conversation
Contributor
This makes possible to use for..of loop with buffers. Also related keys, values and entries methods are added for feature parity with Uint8Array. This is basically the code from v8 array iterator implementation minus spec stuff.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactionsDtrace probes were removed from libuv recently, but their usage by node was not completely removed, causing build breaks on SmartOS. Even though the build is working on other platforms, these probes are not fired by libuv anymore, so there's no point in using them on these platforms too. Reviewed-by: Trevor Norris <[email protected]> PR-URL: nodejs/node-v0.x-archive#8847 Reviewed-by: Trevor Norris <[email protected]> Marking these two tests as flaky, since they have been failing intermittenly in recent builds: test-debug-signal-cluster test-cluster-basic PR-URL: nodejs/node-v0.x-archive#8546 Reviewed-By: Colin Ihrig <[email protected]> PR-URL: nodejs/node-v0.x-archive#8845 Reviewed-by: Trevor Norris <[email protected]> Clarify the fd option: it is preferred to the path parameter, omits the "open" event if given, and is available on WriteStreams as well. PR-URL: nodejs/node-v0.x-archive#7707 Fixes: nodejs/node-v0.x-archive#7707 Fixes: nodejs/node-v0.x-archive#7708 Fixes: nodejs/node-v0.x-archive#4367 Reviewed-By: Chris Dickinson <[email protected]> Reviewed-By: Fedor Indutny <[email protected]> PR-URL: nodejs/node-v0.x-archive#6442 Fix Interface.setBreakpoint() to correctly handle an attempt to set a breakpoint in the current script when there is no current script. This usually happens when the debugged process is not paused. Fixes: nodejs/node-v0.x-archive#6453 PR-URL: nodejs/node-v0.x-archive#6460 Reviewed-By: Chris Dickinson <[email protected]> Fix a Windows-only build error that was introduced in commit 1183ba4 ("zlib: support concatenated gzip files"). Rename the NO_ERROR and FAILED enumerations, they conflict with macros of the same name in <winerror.h>. PR-URL: nodejs/node-v0.x-archive#8893 Reviewed-By: Fedor Indutny <[email protected]> Reviewed-By: Rod Vagg <[email protected]> Reviewed-by: Timothy J Fontaine <[email protected]> In cases where many small writes are made to a stream lacking _writev, the array data structure backing the WriteReq buffer would greatly increase GC pressure. Specifically, in the fs.WriteStream case, the clearBuffer routine would only clear a single WriteReq from the buffer before exiting, but would cause the entire backing array to be GC'd. Switching to [].shift lessened pressure, but still the bulk of the time was spent in memcpy. This replaces that structure with a linked list-backed queue so that adding and removing from the queue is O(1). In the _writev case, collecting the buffer requires an O(N) loop over the buffer, but that was already being performed to collect callbacks, so slowdown should be neglible. PR-URL: nodejs/node-v0.x-archive#8826 Reviewed-by: Timothy J Fontaine <[email protected]> Reviewed-by: Trevor Norris <[email protected]> Add documentation for the callback parameter of http.ClientRequest's and http.ServerResponse's end methods. Signed-off-by: Julien Gilli <[email protected]>
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/Additionaly/Additionally/
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks!
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
vkurchatkin
force-pushed
the
iterable-buffer
branch
from
43ff8f6 to
685ec25
Compare
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm curious -- can iterators reuse results? If so that might be ideal, otherwise for large buffers we might see a huge number of throwaway objects generated when iterated with
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't using flyweights here just be reinventing smis, badly? If you really wanted to do that, though, you could probably do it in the
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I hope this would be somehow optimized eventually. I mean, the whole
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In my unscientific benchmarking, using a cache makes it about 15% faster. Benchmark: var buf = Buffer(1 << 26), idx = 0; buf.fill(0); // Touch memory, force delayed allocation. for (var b of buf) buf[idx++] = b; Cache: diff --git a/lib/buffer.js b/lib/buffer.js index 9149b65..eb75761 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -969,6 +969,11 @@ function BufferIteratorResult(value, done) { this.done = done; } +var cache = new Array(256); + +for (var i = 0; i < cache.length; i += 1) + cache[i] = new BufferIteratorResult(i, false); + BufferIterator.prototype.next = function() { var buffer = this._buffer; var kind = this._kind; @@ -980,7 +985,7 @@ BufferIterator.prototype.next = function() { this._index++; if (kind === ITERATOR_KIND_VALUES) - return new BufferIteratorResult(buffer[index], false); + return cache[buffer[index]]; if (kind === ITERATOR_KIND_ENTRIES) return new BufferIteratorResult([index, buffer[index]], false); Peak RSS and the number of page faults with that benchmark are consistently and repeatedly 2-3% lower so it makes sense that it's faster. On a related topic, it would be good to add one or two benchmarks in benchmark/buffers/
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @othiym23 ah, I was thinking that each iterator could instantiate a single @vkurchatkin In that these objects will probably only exist in the new-generation pool and be quickly GC'd, it's optimized, though it would still increase GC pressure (I think.) If we can get away it, I imagine only creating two objects per iteration (vs. N + 1) would be less expensive.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @chrisdickinson I was actually thinking that it's possible to avoid object creation at all in var b = new Buffer(255); for (var i = 0; i < 255; i++) b[i] = i; var it = b[Symbol.iterator](), r; while ((r = it.next()) && !r.done) r.value = Math.floor(Math.random() * 255);
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there anything in the spec that forbids making the the cached objects immutable with
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, I think result object are supposed to be simple mutable data objects (https://people.mozilla.org/~jorendorff/es6-draft.html#sec-createiterresultobject). It is not specified anywhere that custom iterators should work the same way (https://people.mozilla.org/~jorendorff/es6-draft.html#sec-iteratorresult-interface), but I think they should.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Object.freeze is definitely allowed.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
vkurchatkin
force-pushed
the
iterable-buffer
branch
from
685ec25 to
299bf12
Compare
Contributor
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Member
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Contributor
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Contributor
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Contributor
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo: s/itertation/iteration/ (or maybe just 'method')
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style: indent error.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
vkurchatkin
force-pushed
the
iterable-buffer
branch
2 times, most recently
from
7ef9fe7 to
60cdc32
Compare
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style: wrong indentation.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
vkurchatkin
force-pushed
the
iterable-buffer
branch
from
60cdc32 to
00a04e3
Compare
Contributor
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
syg
pushed a commit
to syg/node
that referenced
this pull request
…ces. (nodejs#204) These tests will be re-enabled once a V8 CL https://crrev.com/c/5907815 lands. The CL changes the way such entries are displayed in stack traces to Constructor.blah.
bakkot
pushed a commit
to bakkot/node
that referenced
this pull request
…ces. (nodejs#204) These tests will be re-enabled once a V8 CL https://crrev.com/c/5907815 lands. The CL changes the way such entries are displayed in stack traces to Constructor.blah.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ReviewersNo reviewsUh oh!
There was an error while loading. Please reload this page. AssigneesNo one assignedLabels
buffer
ProjectsMilestoneNo milestoneDevelopmentSuccessfully merging this pull request may close these issues. Uh oh!
There was an error while loading. Please reload this page. 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. |