-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Add serialization support for queries, highlight configs #2594
base: master
Are you sure you want to change the base?
Conversation
65fa489
to
0e3e39c
Compare
There is a lot of interest in queries (de)serialization and a more robust solution will be implemented that covers more use cases with better deserialization performance. |
That sounds great. I wonder if it would make sense to merge something like this PR in the interim, seeing as how my original issue is nearly a year old now. Even if it isn't particularly robust, doesn't cover every use-case (which are missing?), and could be improved performance-wise, it still provides functionality that dramatically changes the utility of tree-sitter by immediately making it usable in cases where it was previously prohibitive due to performance impacts. Nevertheless, is there anywhere I can follow those efforts and potentially contribute? I'd love to avoid duplicating effort, and of course, maintaining a fork just to have something on crates.io. |
This commit adds two new functions to query.c useful for (de)serialization. In an effort to address issue tree-sitter#1942
0e3e39c
to
ee2986a
Compare
This is a continuation of #2374 which fully resolves #1942.
The approach here is to expose serializable versions of queries and highlight configurations instead of attempting to provide serialized versions directly. This enables the consumer to serialize the structures as they wish, and importantly, to do so in a way that respects things like byte order properly.
The above is exposed via new
serializable()
anddeserialize()
methods onQuery
andHighlightConfiguration
andSerializable{Query,HighlightConfiguration}
structures which implementserde::{Serialize, Deserialize}
when the newly supportedserde
feature is enabled. I have successfully used this API to deserialize over 100 of highlight configurations in ~3 ms. This compares to ~3000ms to generate the configurations directly, or a 1000x improvement. The resulting structures can be used immediately without any additional preprocessing.I should mention that there are a few concerns with the exact approach from #2374, which is replicated here:
const char *src
array's size is sufficient. Previously, asize
argument was passed in but was unused. We should use the argument to check against the expected size.