-
Notifications
You must be signed in to change notification settings - Fork 30
perf: do not call varint.decode() if buffer has 0 length #125
Conversation
@vasco-santos could you have a look at this PR? It's quite important for lodestar as it causes a performance issue. Thanks! |
@tuyennhv is it possible to add a test for this so a regression will not be caused? |
Merging master into this branch will get you gh actions and remove travis too for more reliable CI. |
fa2bfa0
to
147e135
Compare
so I looked into I can't think of a good way to test the change unless:
let me know if it's worth to do that for this simple change or if there's any better ways to test the change |
@achingbrain also please help approve the gh workflow, thanks. |
src/coder/decode.js
Outdated
while (true) { | ||
if (!this._buffer.length) { | ||
// after consuming the whole length, _buffer has 0 length so don't want to bother varint | ||
break | ||
} |
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.
while (true) { | |
if (!this._buffer.length) { | |
// after consuming the whole length, _buffer has 0 length so don't want to bother varint | |
break | |
} | |
while (this._buffer.length) { |
Suggested refactor - this way there's no new branch added so no need to add a test to ensure it's being hit.
Please can you check this against your CPU profiling to ensure it gives you the same performance improvement?
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.
yeah this is great, should be the same with no new branch added 👍 . Thanks @achingbrain !
Shipped in |
Motivation
varint.decode()
function time is used to handlevarint.decode()
RangeError because the buffer length is 0