ampproject / amphtml

The AMP web component framework.
https://amp.dev
Apache License 2.0
14.89k stars 3.89k forks source link

amp-bind: remove the need for parsing in most cases #27441

Open samouri opened 4 years ago

samouri commented 4 years ago

summary

amp-bind is one of the most widely used methods for enabling interactivity in AMP pages. On low-end devices, it can take ~1.2s to initialize. This is largely due to the cost of starting up the webworker and parsing all of the bind expressions on the page.

Lately, I've been wondering if it could be possible for us to move some of this work to the AMP Optimizer.

assumption The vast majority of documents do not use mustache interpolation within their bind expressions. Since mustache rendering is done at runtime, they would be impossible to precompute.

optimization

We can skip expression parsing (and even downloading the parser) by computing the ASTs for each expression on the page in the AMP Optimizer. We can place a map from expression string to AST in an inline script tag on the page, with a verifiable/validatable hash.

TODOs:

Does this idea make any sense? cc @choumx

dreamofabear commented 4 years ago

I like where your head's at. :)

A less ambitious version 0 of this could be to add i-amphtml-binding attribute to all elements with a binding attribute to remove the cost of TreeWalker.

jridgewell commented 4 years ago

A less ambitious version 0 of this could be to add i-amphtml-binding attribute to all elements with a binding attribute to remove the cost of TreeWalker.

I'd love for us improve this! We can use both a cache transform and AmpOptimizer to accomplish.

samouri commented 4 years ago

@jridgewell to write up an idea about detached iframes