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
aa async resolver #1074
base: main
Are you sure you want to change the base?
aa async resolver #1074
Conversation
packages/aa/test/benchmark1.spec.js
Outdated
@@ -1,7 +1,7 @@ | |||
const { realpathSync, lstatSync } = require('node:fs') |
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 moved/changed in a different PR. I need to rebase and clean up.
* @param {(item: T) => Promise<any>} mapper | ||
* @returns {Promise<void>} | ||
*/ | ||
async function runParallelMax(parallelMax, items, mapper) { |
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.
note: this function could be much more sophisticated so that it tracks which async jobs finished and starts new ones as they do. The jobs are similar enough to each other tho, that it might not bring a lot of improvement to the execution time.
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.
update - quick test of the concept:
async function runParallelMax(parallelMax, items, mapper) {
items = items.reverse()
return new Promise((resolve, reject) => {
let promises = 0
const boop = () => {
if (items.length === 0) {
if(promises === 0) resolve()
return
}
const p = mapper(items.pop())
promises++
p.then(()=>{
promises--
boop()
}, reject)
}
for (let i = 0; i < parallelMax; i++) {
boop()
}
})
}
with this implementation it's a few percent slower, so there's not much to gain from smarter parallelization
BREAKING CHANGE: change in `resolver` option type
60d2c57
to
448fbd2
Compare
Fixes #1073
Introduces a major change in the programmatic API but to a parameter that was seldom used. Will require a major bump but no consequences in adoption or such.
Performance is almost unaffected.