Repository navigation
Serialize using post-order traversal - #4269
Conversation
|
I took a quick look this evening, but it's rather hard to tell from the diff so I'll need to look at the generated code. |
|
I wouldn't be surprised if it were a bit slower, but this is a correctness thing. Serializing crashes before we hit the parser-imposed depth limit, meaning we can't serialize every possible tree that is possible to parse. If this is indeed slower, we could probably track a maximum depth and then switch on that to try to guess if we would overflow the stack, but that feels unreliable. |
|
Very minor but the generated Java & Ruby code looks like: private Nodes.GlobalVariableWriteNode loadGlobalVariableWriteNode(NodeStack stack) {
int startOffset = loadVarUInt();
int length = loadVarUInt();
var field_name = loadConstant();
var field_value = stack.pop();
return new Nodes.GlobalVariableWriteNode(startOffset, length, field_name, field_value);
}Would be more readable without that |
|
I benchmarked the total parsing time for railsbench boot: after: So it's something like between 3% (485.0/470.0) and 6% (501.0/472.0) slower, not ideal but close enough. |
|
Thank you for fixing this! |
|
Benchmarks on TruffleRuby Native for completeness: Much faster than on JVM, but the slowdown is higher: 10-11%. Might be worth looking into it (after this PR is merged), because parsing is actually quite a bit slower than translating on Native (on JVM translating dominates like |
This makes it so that you do not have to recurse when serializing and deserializing, making this safe for deep trees.
aad4447 to
c3a3523
Compare
This makes it so that you do not have to recurse when serializing and deserializing, making this safe for deep trees. There's a bit of extension to make lazy def bodies work — we put a marker in the says how much of the node to skip (i.e., the header) and then a length for the body. Other than that it should all be the same.
cc @enebo @eregon I'm definitely not super confident on the Java side, but it seems correct-ish. Let me know what you think. I'm hoping to get this out for 2.0 so we're fully safe for deep trees.