Closed jvasileff closed 8 years ago
First bullet done. Perhaps we could do the second one in a subclass of Editor
?
Is there an advantage to having a subclass that outweighs the maintenance overhead?
I'd hazard to guess that a when using the default editNode() => true
, the overhead of the check would not be measurable.
The big downside to this approach is that
editNode()
can be complex
True, but it can also be simple. I would think that often, a simple => is X;
or => is X|Y|Z;
would be enough. For known X
, Y
, Z
, this would compile down to an instanceof
test (or instanceof || instanceof || …
), and I think I recall reading that HotSpot can often optimize instanceof
down to a single instruction.
The advantage would be to keep Editor
a bit simpler, but I guess that’s a pretty small advantage.
True, but it can also be simple
Agreed. And, editNode()
impls can error on the side of returning true
, to reduce complexity.
Right. So let’s add this…
Second bullet also done. Should I leave this issue open for more suggestions, or close it, and you’ll open new issues for new suggestions?
Great, thanks @lucaswerkmeister!
I'm still interested in any ideas/techniques anyone might have for writing fast Editors, but I'm out of improvement ideas for now, so I'll go ahead and close the issue.
Naive use of
ceylon.ast.core::Editor
is too slow to be used in a compiler. So I'd like to explore ideas to make it fast.that
default Boolean editNode(Node node) => true;
called by default implementations of all non-leaf nodes; returnthat
iffalse
.Here's a somewhat optimized
Editor
that can help serve as an example. This one runs in a little under twice the time of a simple count-nodes visitor on the SDK. A non-optimized Editor takes about 3 or 4 times as long to run.The big downside to this approach is that
editNode()
can be complex and serves no purpose other than optimization.