Revisit PHP representation of AMP validator spec #2769
Labels
Enhancement
New feature or improvement of an existing one
P2
Low priority
Sanitizers
WS:Perf
Work stream for Metrics, Performance and Optimizer
The AMP validator spec is converted from protoascii into PHP via the
bin/amphtml-update.py
Python script. This file tries to only extract the information that is needed for the tag-and-attribute sanitizer, but still, it is large: 451KB—so large in fact that it crashes phpcs: #2767 (comment). Just requiring this file incurs memory usage of +4MB. We could look at splitting up file by tag so that we only load the data for tags that are actually encountered.Stepping back a bit further, we should also consider whether the Python script is the best way to extract the validator spec into PHP. It turns out that @fstanis has worked on making available the validator spec in JSON format: ampproject/amphtml#22528. This would mean at the very least that we could rewrite the spec extraction logic in PHP (or even JS) instead of Python (which has the required protobuf library, though there is probably a PHP protobuf library that could have been used instead). In any case, it is much more comfortable to work with JSON than protoascii, as long as there is no loss of fidelity in the conversion, which is done in
validator/validator_gen_js.py
:Another benefit here is this would avoid us having to download the entire amphtml repo, since the entire spec in JSON format is always available at https://cdn.ampproject.org/v0/validator.json
This JSON file is only ~250KB as opposed to an archive export of the amphtml repo which is 100MB+.
The text was updated successfully, but these errors were encountered: