-
Notifications
You must be signed in to change notification settings - Fork 296
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
Resolver API #519
Resolver API #519
Conversation
Thank you for putting this together, I was able to try it out for our use case and compare it to the optmizaiotn you suggested in #514 (comment). I used hey to test our service with the various implementations. Version 1The actual code we have is a bit more involved, but roughly this is the current implementation we have with your optimization from #514 let _resolver: Resolver
const script = new VMScript(`module.exports = require('./bundle.js');`);
function render(args) {
const vm = createVM();
const handler = vm.run(script);
return handler(args);
}
function createVM() {
const vm = new NodeVM({ require: { external: true, root: './'} })
cacheResolver(vm)
return vm
}
function cacheResolver(vm: NodeVM) {
if (!_resolver) {
_resolver = vm._resolver
} else if (vm._resolver) {
try {
Object.assign(vm._resolver, {
packageCache: _resolver.packageCache,
scriptCache: _resolver.scriptCache,
})
} catch (error) {
report(error)
throw error
}
}
} Results0.1122 secs / request @ p50 for 100 requests with concurrency 1
Version 2Again, this cuts out some details, but this is roughly what my implementation of this let _resolver: Resolver
const script = new VMScript(`module.exports = require('./bundle.js');`);
function render(args) {
const vm = createVM();
const handler = vm.run(script);
return handler(args);
}
function createVM() {
const resolver = getResolver()
const vm = new NodeVM({ require: resolver })
return vm
}
function getResolver() {
if(_resolver) return _resolver
_resolver = makeResolverFromLegacyOptions({ external: true, root: './'})
return _resolver
} Results0.1167 secs / request @ p50 for 100 requests with concurrency 1
ConclusionThe API you propose here gives me the same run-time characteristics, and a nicer API 👍 I'd say it's a winner 🏆 |
Thanks for the feedback |
Oh and for comparison, if I don't cache the resolver at all, I eventually start to error if I try to make 100 consecutive requests, but at 19 requests I see the following Results1.7231 secs / request @ p50 for 19 requests with concurrency 1
So you can see that caching the resolver is a huge improvement for us! |
Add resolver API allowing to share resolvers for multiple
NodeVM
instances.A new resolver can be created with
makeResolverFromLegacyOptions
.