java - Java8 slow compiling for interfaces with thousands of default methods with the same name -
given interfaces (which large , generated out of language definitions):
interface visitora { default void visit(asta1 node) {...} ... default void visit(asta2000 node) {...} } interface visitorb extends visitora { default void visit(astb1 node) {...} ... default void visit(astb1000 node) {...} // due language embedding visit methods of visitora // must overwritten @override default void visit(asta1 node) {...} ... @override default void visit(asta2000 node) {...} } interface visitorc extends visitora { default void visit(astc1 node) {...} ... default void visit(astc1000 node) {...} // due language embedding visit methods of visitora // must overwritten @override default void visit(asta1 node) {...} ... @override default void visit(asta2000 node) {...} } interface visitord extends visitorb, visitorc { default void visit(astd1 node) {...} ... default void visit(astd1000 node) {...} // due language embedding visit methods of visitora, // visitorb, , visitorc must overwritten @override default void visit(asta1 node) {...} ... @override default void visit(asta2000 node) {...} @override default void visit(astb1 node) {...} ... @override default void visit(astb1000 node) {...} @override default void visit(astc1 node) {...} ... @override default void visit(astc1000 node) {...} }
now compiling interface visitora (containing of 2.000 overloaded methods) needs 10s. compiling interfaces visitorb , visitorc needs each 1.5 min. but when try compile interface visitord, java 8 compiler needs 7 minutes!
- has idea why needs time compile visitord?
- is because of inheritance of default methods?
- or because of diamond constellation, visitorb visitorc extend both visitora , visitord extends visitorb , visitorc again?
we tried around , following solution helped little bit:
interface visitoraplain { void visit(asta1 node); ... void visit(asta2000 node); } interface visitora extends visitoraplain { ... // has same default methods visitora above } interface visitorbplain extends visitoraplain { void visit(astb1 node); ... void visit(astb1000 node); } interface visitorb extends visitorbplain { ... // has same default methods visitorb above } interface visitorcplain extends visitoraplain { void visit(astc1 node); ... void visit(astc1000 node); } interface visitorc extends visitorcplain { ... // has same default methods visitorc above } interface visitord extends visitorbplain, visitorcplain { default void visit(astd1 node) {...} ... default void visit(astd1000 node) {...} // due language embedding visit methods of visitoraplain, // visitorbplain, , visitorcplain must overwritten @override default void visit(asta1 node) {...} ... default void visit(asta2000 node) {...} @override default void visit(astb1 node) {...} ... default void visit(astb1000 node) {...} @override default void visit(astc1 node) {...} ... default void visit(astc1000 node) {...} }
and compilation time of visitord needs 2 minutes. still lot.
- has idea how reduce compilation time of visitord few seconds?
- if remove 2 extends relation of visitord,
extends visitorbplain, visitorcplain
, compilation time of interface needs 15s - though has 5.000 default methods. need visitord compatible visitorb , visitorc (either direct extension or indirect 1 intermediate plain-interfaces) casting reasons.
i read answers similar question: slow jdk8 compilation there problem seemed generic type inference: "there's severe performance regression in java 8 when comes overload resolution based on generic target typing."
so kind of different, if have tip or explanation why so; thankful.
thank you, michael
the credit answer goes @brian goetz.
i created dummy test, once visit
methods overwritten , overloaded, @ other time visitx
methods got different names.
and outcome more amazing thought: when overloading , overwriting visit
methods, compiler needed 30 minutes! when renamed visit
methods uniquely inside 1 visitor class, compiler needed 46 seconds.
here source code dummy test: https://drive.google.com/open?id=0b6l6k365belnukvymhznz0dgrek
and here screenshots compile time @ computer: visitorn
contains overloaded , overwritten visit
methods. visitorg
contains optimized visitx
methods, overwritten not overloaded anymore.
using "plain" approach different visitx
methods, compiling visitor_s
, visitorplain_s
needs 22 seconds (being twice fast approach overloading directly default visitx
methods). visitor_s
has default
methods, extends visitorplain_s
having no default
methods. visitorplain_s
extends other "plain" visitors without default
methods.
but still not understand -- theoretical interest, fact bridge methods: in https://docs.oracle.com/javase/tutorial/java/generics/bridgemethods.html bridge methods occur doe type erasing, in example had no generics , type erasing should not play role @ all. - maybe has explanation why still maters.
Comments
Post a Comment