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

Use struct array for feature id maps and deserialize on the main thread #7015

Closed
wants to merge 1 commit into from

Conversation

asheemmamoowala
Copy link
Contributor

@asheemmamoowala asheemmamoowala commented Jul 24, 2018

Follow up from #7011. The feature id map adds significant size to the JSON transfer from WebWorkers to the main thread.

Push all feature id and paint buffer offsets into a struct array and deserialize into an object/map on the main thread.

I've introduced a Float64 type for explicit support of feature ids which are uint64_t in native.

cc @ChrisLoer @ansis @mourner

@@ -175,6 +176,18 @@ createStructArrayType('feature_index', createLayout([
{ type: 'Uint16', name: 'bucketIndex' }
]), true);

createStructArrayType('paint_buffer_offset', createLayout([
// the index of the feature in the original vectortile
{ type: 'Float64', name: 'featureId' },
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Corresponds to uint64_t in native

Copy link
Contributor

Choose a reason for hiding this comment

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

I still confused by this. What's the underlying type defined in the vector tile spec? A Float64 can't represent every uint64_t.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The vector tile spec doesn't define a type AFAICT. Native vt libraries use a unint64_t to represent ids. The vectortile.js library uses a number type to represent the id, which I believe has the same precision issue as Float64 does here.

Copy link
Contributor

Choose a reason for hiding this comment

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

The feature IDs in the .proto file of the current vector tile spec are 64-bit unsigned integers, although this should have been mentioned in the text too. GeoJSON prefers string IDs, so for VT3 we are discussing generalizing IDs to any representable type and would appreciate input on what is feasible in client code.

Copy link
Contributor

Choose a reason for hiding this comment

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

Huh yeah JS's Number.MAX_SAFE_INTEGER == 2^53 - 1 so technically that's a bug in our current implementation... although apparently we've gotten this far without hearing anyone complain about the feature ID 2^54 not working.

Copy link
Contributor Author

@asheemmamoowala asheemmamoowala Jul 24, 2018

Choose a reason for hiding this comment

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

@ChrisLoer that limit is for Integers. But Number is always a double, with Number.MAX_VALUE == 1.79E+308 . In order to use a large Number in a typed array, as is the case here, the array type should be large enough to accommodate uint64_t. Float64 is the only type that can do that here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created #7020 to track the feature ID bit-size discrepancy.

@@ -22,7 +22,8 @@ const AttributeType = {
Uint16: 'UNSIGNED_SHORT',
Int32: 'INT',
Uint32: 'UNSIGNED_INT',
Float32: 'FLOAT'
Float32: 'FLOAT',
Float64: 'FLOAT'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added this for Flow. Float64 shouldn't be used for vertex buffers.

@asheemmamoowala asheemmamoowala added the performance ⚡ Speed, stability, CPU usage, memory usage, or power usage label Jul 24, 2018
@asheemmamoowala asheemmamoowala changed the title WIP: Use struct array for feature id maps and deserialize on the main thread Use struct array for feature id maps and deserialize on the main thread Jul 24, 2018
@asheemmamoowala
Copy link
Contributor Author

I'm not sure if this change has performance benefits. Even though it does reduce the JSON (non-TypedArray) size for higher zoom tiles, I couldnt measure or perceive improvements (less jank) in panning or zooming animations.

Pan and Zoom animations over 10s both seem to drop more frames (as compared to master). My guess is that deserializing the idMap in ProgramConfiguration affects the main thread, but I havent figured out a way to measure that additional deserialization cost vs any savings from transferring the id map as a TypedArray.

Tested with the map centered over a dense part of NYC ([-73.95327, 40.58377]) with the 3d-buildings dataset that includes unique ids for all building polygons.

@mourner @ChrisLoer any thoughts on how else to measure this change's performance impact?

@ChrisLoer
Copy link
Contributor

any thoughts on how else to measure this change's performance impact?

Can you do before/after JS profiler captures of the same 10 second animation, and look for changes in time spent in Actor.receive vs time spent in the feature deserialization code?

Might also be interesting to look at the flame chart, find long frames, and just look for qualitative differences before/after.

@asheemmamoowala
Copy link
Contributor Author

Closed in favor of #7132

@mourner mourner deleted the serialize-feature-id-map branch August 1, 2019 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance ⚡ Speed, stability, CPU usage, memory usage, or power usage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants