-
Notifications
You must be signed in to change notification settings - Fork 0
Idea: use "packed ASTs" #8
Comments
What's the purpose of the BiTable though? Do JSON keys get stored there? Note currently every JNode object has a table containing the ids of its key nodes. |
You need both the |
thanks for the explanation and the proposal, I will study the compiler source more and I will create a prototype eventually. |
And yes, JSON keys get stored in there too, effectively compressing the key-space, every key is stored only once. |
Oh and one more thing: What I'm proposing here is in the end less code than your current solution, there is really just a single |
Yes, I am aware, it sounds ideal. Regarding the API, previously I just grouped the |
I don't know exactly but my PackedJson distinguishes between JsonTree and JsonNode and it worked reasonably well. The API could also offer a JsonBuilder type. |
New repo is here: https://github.com/planetis-m/packedjson2 its wip. |
Awesome! Looks good! |
Sorry not much progress last week but I am planning on resuming the next. I am kind of clueless from this point onward. How does a JsonBuilder definition/api look like? Note I have made type
JsonNode* = object
k: JsonNodeKind
a: NodePos
t: ref JsonTree My worries are: 1. too much duplication of information, the kind field is also stored in the JsonTree.nodes seq, 2. a pretty hefty JsonNode type (sizeof is 24 bytes) and 3. too many indirections, calling There is also the issue of taking a unsigned LitId and casting it to int32 then using the lowest 3 bit for the kind. I suppose bitabs needs some refactoring, first is there a reason for reserving Hope it makes sense and sorry for the long text. |
The JsonBuilder exists to keep a seq of PatchPos so that you can do more easily:
Nah, just use a distinct int that indexes into the JsonTree.
No, it's a legacy and not required. Cannot be too hard to remove it. |
Have you tried this design:
The crucial idea here is that atoms use 'operand' bits to index into the 'atoms' BiTable while compound nodes use it to store the total number of children. Via some clever arithmetic operations you can easily compute the ith-child anyway. See my PackedAST code in compiler/ic.
This should be close to the optimum design. The API on top should encourage efficient operations (don't use random access, iterate over the tree instead).
The text was updated successfully, but these errors were encountered: