ampproject / ampproject/amphtml
amp-bind: remove the need for parsing in most cases
- Dominant language
- JavaScript
- Stars
- 14.9k
- Forks
- 4.1k
- PR merge metrics
- No merged PRs in 30d
Description
**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:
- [x] measure current time to init
- [ ] measure how much of that time is spent parsing
- [ ] measure how many bytes would be saved by not including the bind parser
---
Does this idea make any sense? cc @choumx
Contributor guide
Research direction
No files or tests are named. Start by measuring amp-bind initialization, the share spent parsing expressions, and the bytes saved by omitting the parser. Done would require validating the proposed AMP Optimizer approach and defining how expression ASTs and their hash would be safely supplied at runtime.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend, performance
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100