-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Partials are too slow #1991
Comments
Some new benchmarks with the current 4.x branch + #2041. This benchmark mimics rendering eg. a list of items using partials, where each partial calls multiple helpers. The helpers and partials are essentially no-ops to measure Handlebars overhead. With version 4.3.0, performance regressed due to the security fixes. With the new changes, we are
const { setTimeout } = require('timers/promises');
const Handlebars = require(
process.argv[2] ? `./handlebars-${process.argv[2]}` : './lib/index.js'
);
// https://unpkg.com/[email protected]/dist/handlebars.js
// https://unpkg.com/[email protected]/dist/handlebars.js
async function main() {
const count = 1000;
Handlebars.registerPartial('partial', `
{{helper this}}
{{helper this}}
{{helper this}}
{{helper this}}
{{helper this}}
`);
Handlebars.registerHelper('helper', function() {
return this + 1
});
const items = [];
for (let i = 0; i < count; i++) {
items.push(i);
}
const template = Handlebars.compile(`
{{#each items}}
{{> partial}}
{{/each}}
`);
// Warm up
for (let i = 0; i < 100; i++) {
template({ items });
}
await setTimeout(500);
console.time('partial');
for (let i = 0; i < 10; i++) {
template({ items });
}
console.timeEnd('partial');
}
main(); |
I guess we can close this issue now? |
Yes, I think this is as good as it's going to get for partials. |
While investigating why rendering a few hundred objects was incredibly slow in Handlebars, I found that the root cause is partials (profiling showed most of the time spent in
invokePartialWrapper
, a lot of time is also spent inextend
). See the following code:Output:
Partials are 120x times slower than a regular function call.
Extended benchmark with indenting
The text was updated successfully, but these errors were encountered: