Skip to content

[Bug]: Severe Performance Regression in toString #6528

@hunterpayne

Description

@hunterpayne

Describe the bug

So apparently, the PrettyPrinter can now change the contents of an element. Ignoring if this is a good idea or not (seems pretty bad at first glance), this means that the toString method now clones itself before passing itself to the PrettyPrinter. This results in significantly reduced performance when turning an element back into code.

Perhaps a different, faster method for producing code or perhaps rethink allowing the PrettyPrinter to change an Element's contents.

Either way, please make the toString method faster and cause it not to use so much memory. Perhaps even make it not use String but instead take a StringBuilder so the strings don't get internalized and consume so much memory.

Source code you are trying to analyze/transform

// The biggest Java file you can find

Source code for your Spoon processing

Launcher l = new Launcher();
l.addInputResource(new FileSystemFile("ReallyBig.java"));
CtType tpe = l.buildModel().getAllTypes().get(0);
System.out.println("time to start the profiler");
Thread.sleep(15000);
tpe.toString();

Actual output

N/A

Expected output

N/A

Spoon Version

11.2.1

JVM Version

java 17

What operating system are you using?

Ubuntu

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions