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
Replace buffer implementation with standard Uint8Array #35
Comments
Upstream issue: nodejs/node#6744 |
I think the main reason to use Buffer instead of Uint8Array was that native |
Yeah, just confirmed by running the benchmark in Node on both:
Writing is surprisingly slightly faster, but reading performance drop is dramatic (almost twice as slow) — we can't allow such a regression. |
It's on the writing side that I lost most of a day to debugging a subtle difference between Can we use |
I don't yet see a good solution here. We can't switch the shim for writing only because you create a Pbf object once and can then mix read/write on it. And converting from Would it be acceptable to leave the current implementation but add a warning to the |
Nobody will find that comment until they've already spent a long time debugging some obscure issue. You've already benchmarked that using |
Workaround in gl-js: mapbox/mapbox-gl-js@57be2ce |
As I mentioned earlier, we can only switch to Uint8Array for both read/write at the same time, and making reads 2 times slower is not an option. I'm investigating why exactly it's slower, but can't promise to find an actionable cause. |
I still think we should just use and accept the performance of The current code forces copying the data in the browser when you do |
Working on this. Managed to get the Uint8Array decoding perf drop to ~9% from ~46%. |
Refs mapbox/pbf#35 (comment) A copy, rather than a transfer, _is_ needed when sending the rawTileData to the main thread. In that case, don't use a transferrable.
Refs mapbox/pbf#35 (comment) A copy, rather than a transfer, _is_ needed when sending the rawTileData to the main thread. In that case, don't use a transferrable.
Refs mapbox/pbf#35 (comment) A copy, rather than a transfer, _is_ needed when sending the rawTileData to the main thread. In that case, don't use a transferrable.
Refs mapbox/pbf#35 (comment) A copy, rather than a transfer, _is_ needed when sending the rawTileData to the main thread. In that case, don't use a transferrable.
The conditional use of node's
Buffer
versus a shim based onUint8Array
leads to subtle incompatibilities between node and the browser. I just spent a couple hours debugging an issue in mapbox-gl-js that stems from the following difference:In the browser, this prints 16, as expected. In node, it prints 8192.
To eliminate this gotcha, pbf should use standard
Uint8Array
's everywhere, and drop usage ofBuffer
.The text was updated successfully, but these errors were encountered: