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

Dead code removal - Expression.serialize #1312

Closed
drwestco opened this issue Jun 20, 2022 · 9 comments
Closed

Dead code removal - Expression.serialize #1312

drwestco opened this issue Jun 20, 2022 · 9 comments

Comments

@drwestco
Copy link
Contributor

Each type of Expression has an implementation for a per-instance serialize method. From a cursory inspection of the project, these methods are only ever called from expression.test.ts - never from production code. Serialization of expressions via style properties is only done by serializing the raw values. Serialization across the web worker boundary behaves similarly - if a class implements a static serialize method, it will be called; if not, raw value serialization is performed.

There's a decent amount of code cleanup that can occur here, if all of these per-expression serialize methods can indeed be removed. Need to perform more thorough investigation to verify the code is dead, revise expression.test.ts, and then remove the serialize methods.

@drwestco
Copy link
Contributor Author

History of Expression.serialize in the MB GL JS code: mapbox/mapbox-gl-js#6253

It's truly there only to support the tests, for parity with the same tests in the native codebase. I don't fully understand how a JS serialization implementation helps the native/JS workflow, and I certainly don't see the logic in releasing code that's never executed.

@wipfli
Copy link
Contributor

wipfli commented Jun 21, 2022

Can you share an example of code that is not used?

@xabbu42
Copy link
Contributor

xabbu42 commented Jun 23, 2022

There is code in maplibre-gl-native (https://github.com/maplibre/maplibre-gl-native/blob/ca5810f61fde26d0fbccbe4d48d4c771d02e460f/expression-test/expression_test_parser.cpp#L341) which uses the maplibre-gl-js tests for expressions. I did not have the time to dig in further or actually run that, but it seems we at least once had a common test suite for expressions in maplibre-gl-js and maplibre-gl-native. That would be highly valuable to ensure the compatibility of the two implementations and should not be given up lightly.

As I understand it so far, in maplibre-gl-native the serialize methods are used and need to be tested, but as it shares its test-suite with maplibre-gl-js there needs to be an implementation in both projects so the same tests run for both projects, or something like that.

@drwestco
Copy link
Contributor Author

From what I understand, if the test.json doesn't have a section for the serialized representation, that step will be ignored. I think that's as it should be - there's no need for native's serialized format to match that of JS, especially since JS never actually serializes an expression!

There's additional testing that the output matches, both against the original parsed expression, and the expression after a round trip through serialization. That's also good, as it verifies expression compatibility between JS and native.

@HarelM
Copy link
Collaborator

HarelM commented Jun 23, 2022

Also, if this serialization code is needed in the native side (which I don't think it's the case) then it should be there.
The fact that both use the same library for test data is great for matching, but this was not changed in the linked PR.
In any case, I think this issue is resolved, feel free to continue the discussion.

@HarelM HarelM closed this as completed Jun 23, 2022
@drwestco
Copy link
Contributor Author

It looks like this portion of the native tests may now be broken, as it pulls the expected serialized format from the **/test.json files in the gl-js tree. https://github.com/maplibre/maplibre-gl-native/blob/ca5810f61fde26d0fbccbe4d48d4c771d02e460f/expression-test/expression_test_runner.cpp#L176

@HarelM
Copy link
Collaborator

HarelM commented Jun 23, 2022

But the expression is defined in the layer, isn't it?isn't it the same?

@HarelM
Copy link
Collaborator

HarelM commented Jun 23, 2022

Also note that native is using an older version of this repo, when this will be updated for the sharers (which is a huge effort) we'll probably need to take care of this as well.
But in theory, I don't mind having this property in the expected json file.

@drwestco
Copy link
Contributor Author

Ah. I removed the "serialized" sections from each of the JSON files, since JS has no way to generate those now. Native test code should be updated to handle this. If it's important to verify the serialized output doesn't change, instead of just checking that the output is correct after round-tripping, that portion of the test data should be in the native repo.

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

No branches or pull requests

4 participants