Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance of the java-generator #4865

Closed
andreaTP opened this issue Feb 10, 2023 · 1 comment 路 Fixed by #4867
Closed

Improve performance of the java-generator #4865

andreaTP opened this issue Feb 10, 2023 · 1 comment 路 Fixed by #4867
Assignees
Milestone

Comments

@andreaTP
Copy link
Member

andreaTP commented Feb 10, 2023

Suggestion from @mariofusco as he used async profiler against the java-generator, thanks for the amazing work 馃檹 !

He noticed that one possible optimization would be to reduce the amount of work that JavaParser should do when parsing plain Strings e.g. here :

clz.addImplementedType("io.fabric8.kubernetes.api.model.KubernetesResource");

can be more efficient narrowing down the scope of the JavaParser string parsing:

clz.addImplementedType( toClassOrInterfaceType( "io.fabric8.kubernetes.api.model.KubernetesResource" ) );
@mariofusco
Copy link
Contributor

mariofusco commented Feb 10, 2023

Just to be clear that toClassOrInterfaceType is not a JavaParser method, but an utility method that for instance in Drools has been implemented in this way.

So you can simply add the same method to your code base and reuse it:

    public static ClassOrInterfaceType toClassOrInterfaceType( String className ) {
        String withoutDollars = className.replace("$", "."); // nested class in Java cannot be used in casts
        return withoutDollars.indexOf('<') >= 0 ? StaticJavaParser.parseClassOrInterfaceType(withoutDollars) : new ClassOrInterfaceType(null, withoutDollars);
    }

Also note that when you're sure that the type name doesn't refer to an inner class or has generics, as in your example, you can rewrite that statement in an even simpler and more efficient way as it follow:

clz.addImplementedType(new ClassOrInterfaceType(null, "io.fabric8.kubernetes.api.model.KubernetesResource"));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants