ceylon / ceylon.ast

Apache License 2.0
18 stars 3 forks source link

make Editor lightning quick #111

Closed jvasileff closed 8 years ago

jvasileff commented 8 years ago

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.

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.

lucaswerkmeister commented 8 years ago

First bullet done. Perhaps we could do the second one in a subclass of Editor?

jvasileff commented 8 years ago

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.

lucaswerkmeister commented 8 years ago

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.

lucaswerkmeister commented 8 years ago

The advantage would be to keep Editor a bit simpler, but I guess that’s a pretty small advantage.

jvasileff commented 8 years ago

True, but it can also be simple

Agreed. And, editNode() impls can error on the side of returning true, to reduce complexity.

lucaswerkmeister commented 8 years ago

Right. So let’s add this…

lucaswerkmeister commented 8 years ago

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?

jvasileff commented 8 years ago

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.