Implement ConstReference
optimization
#109
Merged
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.
A const reference cannot change, so we do not need to emit an updating opcode for them.
For example:
In this case, the conditional is a literal, so it is impossible for the the {{#if}} to flip from default to inverse on the update pass, hence there is no need to emit an
Assert
for the conditional value.While this in itself is pretty rare, it is quite common for this to happen indirectly. For example:
In this case, there is no need to emit updating opcodes for the attributes and content curlies.
This optimization also composes nicely, allowing things like
EmberID
orhasBlock
to return const references and drop the unnecessary work.This is also quite noticeable because we don't currently distinguish between "component element" (whose attributes can be "clobbered" by the invocation) and a regular element, so all the "static" attributes still go through the merging policy object. (See 07069c6) With this optimization, we at least do not pay an extra cost for those static attributes on update. (We should come back to optimize non-component elements more.)
Another example: