ceylon / ceylon.ast

Apache License 2.0
18 stars 3 forks source link

optimize Node.visitChildren() #107

Closed jvasileff closed 8 years ago

jvasileff commented 8 years ago

Node.visitChildren() delegates to transformChildren(), which unnecessarily instantiates a sequence:

    shared Result[] transformChildren<out Result>(Transformer<Result> transformer) => [
        for (child in children)
            child.transform(transformer)
    ];
...
    shared void visitChildren(Visitor visitor) => transformChildren(visitor);

so perhaps visitChildren should be rewritten as:

    shared void visitChildren(Visitor visitor) {
        for (child in children) {
            child.transform(visitor);
        }
    }

based on tests against sdk modules, this has the potential to drop processing times by 40%+ for Visitors that don't perform expensive tasks.

jvasileff commented 8 years ago

I can try this out later.

lucaswerkmeister commented 8 years ago

Done. I call child.visit instead of child.transform, because:

jvasileff commented 8 years ago

Thanks @lucaswerkmeister, this provides a very nice performance boost. After warmup for a node-counting visitor, I'm seeing seeing an improvement from 1.2.0's 79.72ms to a new time of 41.49ms.

Now, this compares to 14.76ms and 14.91ms times using a typechecker visitor as a control. More on that to come...