mapbox / mapbox/geobuf

Decoding slower than JSON.parse()

Open
#114 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
JavaScript
Stars
1k
Forks
86
PR merge metrics
No merged PRs in 30d

Description

I am loading a geojson file of full US Zipcodes over an ajax request, before I was using plain json, I now change it to use geobuf. So I replace the JSON.parse() by a geobuf.decode().

The document says it should be faster:

even faster than native JSON parse/stringify.

However now it is actualy 2 seconds slower.

var req = new XMLHttpRequest();
req.responseType = "arraybuffer";
req.addEventListener("load", function () {

	//var featureCollection = JSON.parse(this.responseText); // Took arround 4s
	var featureCollection = geobuf.decode(new Pbf(this.response)); // takes arround 6s
	//...
});
req.open("GET", url);
req.send();

Am I doing something wrong or is there any way to improve it?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the XMLHttpRequest example in the issue, comparing JSON.parse(this.responseText) with geobuf.decode(new Pbf(this.response)) on the full US Zipcodes GeoJSON. Trace the decode entry point and benchmark both paths to determine whether the slowdown is reproducible and what work would be needed to improve or explain it.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.