Skip to content
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

fix(runtime.js): partials compile not caching #1600

Merged
merged 9 commits into from Nov 18, 2019

Conversation

ole-martin
Copy link
Contributor

Reintroduce assigning env.partials to container.partials if no options.partials is set. Also allow assigning options.partials to container.partials if only that one exists. This solves #1598

Reintroduce assigning env.partials to container.partials if no options.partials is set. Also allow assigning options.partials to container.partials if only that one exists. This solves handlebars-lang#1598
@andersk
Copy link

andersk commented Nov 11, 2019

Perhaps helpers and decorators should also go back to using merge like they did before 2078c72?

@ole-martin
Copy link
Contributor Author

@andersk Afaik they aren't compiled, so there won't be a big difference like with partials, but it will potentially have some speed-up as it will skip the shallow-copy step if not needed. @nknapp what do you think?

@nknapp
Copy link
Collaborator

nknapp commented Nov 12, 2019

I think the overhead of the shallow-copy step is negligible.

#1594 is also related to that place. It makes sure that the helpers-object has a "null"-prototype, because some exploits have used "defineGetter" to do bad things and the "helpers"-object is accessible from the template.

Merging here makes sure that the "helpers"-option is not used "as is" and together with #1594 it ensure the null-prototype (Object.create(null)) for this object, so: No, I would like to leave helpers and decorators as they are.

@ole-martin could you rename the merge-function to something that explains what the function is doing. It's not a simple "merge", but a "merge if needed" or a "first non-null or merge" or something like that. If you find a good name, short yet describing what the function does, please take it. But "firstNonNullOrMerged" would be fine to.

I was confused the first time I read that code and my intention (over time) is to make the Handlebars code more explanatory and clean (not by comments, but by good naming).

@ole-martin
Copy link
Contributor Author

@nknapp Updated function name to "mergeIfNeeded" now 👍

@nknapp
Copy link
Collaborator

nknapp commented Nov 13, 2019

@ole-martin forgive me for delaying this further again. Although I had added some change requests, I haven't had time for a full review yet. And now it is getting too late again. But I will look...

Copy link
Collaborator

@nknapp nknapp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added some change-requests.

Have you made sure that the test fails without you patch?

I will merge the PR without the sinon-changes if you don't want to do that. But it would be nicer that way.

Update: I hope you are not that fast with starting the rebase: I have just added another commit to the 4.x-branch, because "sinon" was not defined as global variable in the eslint-configuration. It now is.

spec/compiler.js Outdated Show resolved Hide resolved
spec/compiler.js Outdated Show resolved Hide resolved
spec/compiler.js Outdated Show resolved Hide resolved
@ole-martin
Copy link
Contributor Author

@nknapp I've moved the test to regressions.js and changed it to use sinon-spy & Handlebars.create(). I've also verified that without the changes to runtime the test fails with

1) Regressions
       GH-1598: Performance degradation for partials since v4.3.0
         should only compile global partials once:
     Error: '4' should === '3'

@nknapp
Copy link
Collaborator

nknapp commented Nov 18, 2019

Great, I'll have another look this evening. But I think its fine now. Thanks.

@nknapp nknapp merged commit 23d58e7 into handlebars-lang:4.x Nov 18, 2019
@ole-martin ole-martin deleted the patch-2 branch December 2, 2019 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants