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

One weird JSON.parse() trick #11098

Merged
merged 1 commit into from
Oct 8, 2021
Merged

One weird JSON.parse() trick #11098

merged 1 commit into from
Oct 8, 2021

Conversation

arindam1993
Copy link
Contributor

@arindam1993 arindam1993 commented Oct 6, 2021

This implements
https://www.youtube.com/watch?v=ff4fgQxPaO0
for the style spec json only. This doesn't implement it for other json objects because with those we would still like to have treeshaking.

The theory is that a static JSON.parse(large_json_string) is much faster than having a large_json_object,this is because a large_json_object is parsed by the full JavaScript parser since it can't know ahead of time if an object is pure-json.
With this change the JS parser skips that entire section since all it sees is a single string. The dedicated json parser underneath JSON.parse can then handle it much faster.
Benchmap is showing a negligible but detectible improvement in workerEvaluateScript which is exactly where we expect to see an improvement.

Screen Shot 2021-10-06 at 2 54 09 PM

@arindam1993 arindam1993 requested review from mourner and ansis October 6, 2021 22:12
Copy link
Member

@mourner mourner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I remember, I didn't pursue this idea earlier because having spec's top-level properties exposed as named exports allowed for better minifying of spec references across the codebase, as you can see by the noticeable non-compressed size increase, but it seems that gzip offsets that and the 50-byte increase is negligible, so we can proceed.

@arindam1993 arindam1993 merged commit b29da33 into main Oct 8, 2021
@arindam1993 arindam1993 deleted the one-weird-json-parse branch October 8, 2021 16:44
katydecorah pushed a commit that referenced this pull request Oct 20, 2021
* main:
  Add touch pan blocker to gesture handling for touch devices (#11116)
  Address accessibility issues (#11064)
  add support for non-mercator projections (#11124)
  Image fallback expressions within paint properties (#11049)
  Replaces EPSG:4326 with OGC:CRS84 in GL JS `LngLat` doc (#11072)
  Add globe view support to heatmap shaders (#11120)
  Exclude flaky test (#11118)
  consistify YOUR_MAPBOX_ACCESS_TOKEN as placeholder string (#11113)
  Allow adding multiple layers to `map.on()` event handler (h/t @omerbn) (#11114)
  render-test-flakiness:clear worker storage (#11111)
  upgrade to supercluster v7.1.4, earcut v2.2.3, vt-pbf v3.1.3, geojson-rewind v0.5.1 (#11110)
  Added v1.13.2 changelog entry (#11108)
  One weird JSON.parse() trick (#11098)
  Fixed doc usage of map.getCenter (#11093)
  s̶y̶m̶b̶o̶l̶-̶c̶l̶i̶p̶ dynamic-filtering with `pitch` and `distance-from-camera` expressions (#10795)
  Update link to transpiling guide (#11096)
  Cherry pick 2.5.1 changelog (#11099)
  Fix an iOS15 issue where Safari tab bar interrupts panning (#11084)
  Fix conditional check for isFullscreen to accommodate Safari (#11086)
  Render tests for #11041 (#11070)
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.

2 participants