-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lib: performance improvement on readline async iterator #41276
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
c467ffe
lib: performance improvement on readline async iterator
05db8ff
lib: undoing accidental changes
Farenheith 3ecee3c
lib: changing once to on in waitNext
Farenheith 83919d2
lib: adding benchmarks for readline iterable
Farenheith 03ac26d
lib: adding different lines multiplier
Farenheith 870b5cf
lib: fixing lint on benchmark
Farenheith ae3325c
lib: adding test to validate slow stream
Farenheith bb6f6ab
lib: adding return and throw implementation to eventsToAsyncIteratorF…
Farenheith 221e239
lib: performance improvement on readline async iterator
b536144
lib: undoing accidental changes
Farenheith 31efb2d
lib: changing once to on in waitNext
Farenheith 0e04a18
lib: fixing lint on benchmark
Farenheith 7a8c3fa
lib: adding test to validate slow stream
Farenheith 156837b
lib: adding return and throw implementation to eventsToAsyncIteratorF…
Farenheith 87da1a2
lib: keep ASCII order on primordials import
Farenheith e7f358a
lib: changing standard for internal constants names
Farenheith d5917c9
lib: unifying on and eventsToAsyncIteratorFactory functions
Farenheith 0143cdf
lib: making firstEventParam interna only
Farenheith 917c51b
lib: refactoring function on
Farenheith 4e8be80
lint: fixing linting problems after merge
Farenheith 610a275
refactor: Apply suggestions from code review
Farenheith e1dd9d3
refactor: readding wrongly removed SymAsyncIterator definition
Farenheith 26d066b
refactor: using ArrayPrototypePush instead of push
Farenheith 835bb5f
lib: fixing FixedQueue.shift calls mistakenly using ArrayPrototypeShift
Farenheith e83baea
lib: fixing faulting PromiseResolve call
Farenheith File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
'use strict'; | ||
const common = require('../common.js'); | ||
const readline = require('readline'); | ||
const { Readable } = require('stream'); | ||
|
||
const bench = common.createBenchmark(main, { | ||
n: [1e1, 1e2, 1e3, 1e4, 1e5, 1e6], | ||
}); | ||
|
||
const loremIpsum = `Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed | ||
do eiusmod tempor incididunt ut labore et dolore magna aliqua. | ||
Dui accumsan sit amet nulla facilisi morbi tempus iaculis urna. | ||
Eget dolor morbi non arcu risus quis varius quam quisque. | ||
Lacus viverra vitae congue eu consequat ac felis donec. | ||
Amet porttitor eget dolor morbi non arcu. | ||
Velit ut tortor pretium viverra suspendisse. | ||
Mauris nunc congue nisi vitae suscipit tellus. | ||
Amet nisl suscipit adipiscing bibendum est ultricies integer. | ||
Sit amet dictum sit amet justo donec enim diam. | ||
Condimentum mattis pellentesque id nibh tortor id aliquet lectus proin. | ||
Diam in arcu cursus euismod quis viverra nibh. | ||
Rest of line`; | ||
|
||
function getLoremIpsumStream(repetitions) { | ||
const readable = Readable({ | ||
objectMode: true, | ||
}); | ||
let i = 0; | ||
readable._read = () => readable.push( | ||
i++ >= repetitions ? null : loremIpsum | ||
); | ||
return readable; | ||
} | ||
|
||
async function main({ n }) { | ||
bench.start(); | ||
let lineCount = 0; | ||
|
||
const iterable = readline.createInterface({ | ||
input: getLoremIpsumStream(n), | ||
}); | ||
|
||
// eslint-disable-next-line no-unused-vars | ||
for await (const _ of iterable) { | ||
lineCount++; | ||
} | ||
bench.end(lineCount); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict'; | ||
|
||
const { | ||
Symbol, | ||
} = primordials; | ||
|
||
const kFirstEventParam = Symbol('nodejs.kFirstEventParam'); | ||
|
||
module.exports = { | ||
kFirstEventParam, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict'; | ||
|
||
require('../common'); | ||
|
||
const runBenchmark = require('../common/benchmark'); | ||
|
||
runBenchmark('readline', { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); |
Oops, something went wrong.
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.
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 part wasn't needed because this method is inherited from the parent prototype