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

Implement ConstReference optimization #109

Merged
merged 5 commits into from
Mar 22, 2016
Merged

Conversation

chancancode
Copy link
Contributor

A const reference cannot change, so we do not need to emit an updating opcode for them.

For example:

{{#if true}}...{{/if}}

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:

{{!-- link-to component layout --}}
<a href="{{@url}}" title={{@title}}>{{@text}}</a>
{{!-- link-to usage --}}
{{link-to url="http://static.string" title="does not change" text="also does not change"}}

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 or hasBlock 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.)

before/after


Another example:

before/after

Godhuda added 5 commits March 22, 2016 15:05
A const reference cannot change, so we do not need to emit an updating
opcode for them.

For example:

```has
{{#if true}}...{{/if}}
```

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:

```hbs
{{!-- link-to component layout --}}
<a href="{{@url}}" title={{@title}}>{{@text}}</a>
```

```hbs
{{!-- link-to usage --}}
{{link-to url="http://static.string" title="does not change" text="also does not change"}}
```

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`
or `hasBlock` to return const references and take advantage of the same
optimization to drop unnecessary update work.
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.

1 participant