[ODLPARENT-39] Code Generation Performance optimization required in YangTemplate (Xtend bug?) Created: 19/Jul/16  Updated: 24/Jan/18  Resolved: 02/Feb/17

Status: Resolved
Project: odlparent
Component/s: General
Affects Version/s: None
Fix Version/s: None

Type: Bug
Reporter: Michael Vorburger Assignee: Michael Vorburger
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Operating System: All
Platform: All


Attachments: File netvirt-mvn-o-Pq-clean-install.jfr.7z     File xtextlib.diff    
Issue Links:
Blocks
blocks MDSAL-54 Topic: Continuos: Improve performance Resolved
External issue ID: 6236

 Description   

I have finally found a moment to performance profile the yangtools/mdsal code generation which occurs during a Maven build by attaching Java Mission Control (JMC) from Oracle JDK (not available on OpenJDK) to a local Maven build.

This is similar to earlier YANGTOOLS-629 but here focusing on looking at Maven itself, Maven plugins, code generation and build - so intentionally excluding the SingleFeatureTest and integration tests etc. using my new -Pq quick profile which local developers are increasingly using now.

Here are the exact steps I've used, if anyone wants to reproduce:

$ export JAVA_HOME=/home/vorburger/bin/jdk1.8.0_92-ORACLE
$ export PATH=$JAVA_HOME/bin:$PATH
$ export MAVEN_OPTS="-XX:+UnlockCommercialFeatures -XX:+FlightRecorder -XX:FlightRecorderOptions=defaultrecording=true,dumponexit=true,dumponexitpath=/home/vorburger/dev/ODL/git/netvirt/mvn.jfr"
$ mvno -o -Pq clean install

The result, attached as netvirt-mvn-o-Pq-clean-install.jfr.7z, is interesting IMHO - unless JMC is totally off, it would seem in [2] that we are spending ca. 20% of total Maven build time of e.g. netvirt in Xtend's org.eclipse.xtend2.lib.StringConcatenation called by YangTemplate, just to build those "verboseClassComments" for 'generated classes will include javadoc comments which re useful for users' with the "This class represents the following YANG schema fragment defined in module ...". The 20% just for that seems a lot - that's just a bunch of String concatenations, through the Xtend helper, which is supposed to "allow for efficient [, indentation aware] concatenation of character sequences" - I think either something is wrong with, or we're using it wrong. But the latter seems unlikely, as [1] YangTemplate looks like a pretty standard plain Xtend template class, to me...

As a first step, I'll try to raise this with the Xmen (Xtend community), to see what they have to say about this.

[1] https://github.com/opendaylight/mdsal/blob/32d45af3bfde08f4e8741632ecab43241831d1fe/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/YangTemplate.xtend

[2] JMC Code top Hot Method TXT copy/paste:

Stack Trace Sample Count Percentage(%)
org.eclipse.xtend2.lib.StringConcatenation.appendSegments(String, int, List, String) 2,407 19.344
org.eclipse.xtend2.lib.StringConcatenation.append(Object, String, int) 2,407 19.344
org.eclipse.xtend2.lib.StringConcatenation.append(Object, String) 2,407 19.344
org.opendaylight.yangtools.sal.binding.generator.impl.YangTemplate.writeListSchemaNode(ListSchemaNode) 674 5.417
org.opendaylight.yangtools.sal.binding.generator.impl.YangTemplate.writeDataSchemaNode(DataSchemaNode) 674 5.417
org.opendaylight.yangtools.sal.binding.generator.impl.YangTemplate.writeDataSchemaNodes(Collection) 609 4.894
org.opendaylight.yangtools.sal.binding.generator.impl.YangTemplate.writeContSchemaNode(ContainerSchemaNode) 423 3.4
org.opendaylight.yangtools.sal.binding.generator.impl.YangTemplate.writeDataSchemaNode(DataSchemaNode) 423 3.4
org.opendaylight.yangtools.sal.binding.generator.impl.YangTemplate.writeDataSchemaNodes(Collection) 223 1.792
org.opendaylight.yangtools.sal.binding.generator.impl.YangTemplate.writeListSchemaNode(ListSchemaNode) 128 1.029
org.opendaylight.yangtools.sal.binding.generator.impl.YangTemplate.writeDataSchemaNode(DataSchemaNode) 128 1.029
org.opendaylight.yangtools.sal.binding.generator.impl.YangTemplate.writeDataSchemaNodes(Collection) 105 0.844
org.opendaylight.yangtools.sal.binding.generator.impl.YangTemplate.writeListSchemaNode(ListSchemaNode) 34 0.273
org.opendaylight.yangtools.sal.binding.generator.impl.YangTemplate.writeDataSchemaNode(DataSchemaNode) 34 0.273
org.opendaylight.yangtools.sal.binding.generator.impl.YangTemplate.writeDataSchemaNodes(Collection) 31 0.249
org.opendaylight.yangtools.sal.binding.generator.impl.YangTemplate.writeContSchemaNode(ContainerSchemaNode) 11 0.088
org.opendaylight.yangtools.sal.binding.generator.impl.YangTemplate.writeDataSchemaNode(DataSchemaNode) 11 0.088
org.opendaylight.yangtools.sal.binding.generator.impl.YangTemplate.generateYangSnipet(SchemaNode) 8 0.064
org.opendaylight.yangtools.sal.binding.generator.impl.BindingGeneratorImpl.createDescription(SchemaNode, String) 8 0.064



 Comments   
Comment by Michael Vorburger [ 19/Jul/16 ]

Attachment netvirt-mvn-o-Pq-clean-install.jfr.7z has been added with description: Oracle Java Mission Control JFR profiling of "mvno -o -Pq clean install" in netvirt on latest netvirt master today (65fb44e) with export MAVEN_OPTS="-Xmx4096m -Xverify:none"

Comment by Michael Vorburger [ 19/Jul/16 ]

> raise this with the Xmen (Xtend community), to see what they have to say

==> https://bugs.eclipse.org/bugs/show_bug.cgi?id=427909

Comment by Martin Ciglan [ 17/Oct/16 ]

any updates on this? Thanks.

Comment by Michael Vorburger [ 17/Oct/16 ]

Martin, thanks for the ping - it's sometimes useful to get reminders...

Dug a little more into this today. In https://git.opendaylight.org/gerrit/#/c/47036/, I'm introducing a proposed new "yang.skip.javadoc" system property, which if true skips the generation of those "verboseClassComments" for 'generated classes will include javadoc comments which re useful for users' with the "This class represents the following YANG schema fragment defined in module ...".

The results are too small to be significant on a single project, but on a multi-module reactor as small as e.g. netvirt/vpnservice this looks very interesting, and makes me thing I'm onto something that is worth digging more into, check this out:

netvirt/vpnservice:
mvn -o -Pq clean package: Total time: 03:14-21 min
mvn -o -Pq -Dyang.skip.javadoc=true clean package: Total time: 02:15-18 min

At the scale of a full ODL (autobuild), this would obviously likely be even more significant.

I'll use this as motivation to reach out to eclipse.org friends about https://bugs.eclipse.org/bugs/show_bug.cgi?id=427909. In the mean time, if we would get https://git.opendaylight.org/gerrit/#/c/47036/ into ODL (and I would follow with an oldparent change to leverage this IFF -Pq), that would probably be something useful in the very short term already.

Comment by Robert Varga [ 25/Oct/16 ]

Michael, is this still being worked on?

Comment by Michael Vorburger [ 31/Oct/16 ]

> Michael, is this still being worked on?

Robert, yup it is; this is proceeding on two levels, as outlined above:

a) https://git.opendaylight.org/gerrit/#/c/47036/ for short-term

b) https://bugs.eclipse.org/bugs/show_bug.cgi?id=427909 for medium term. I've actually discussed that with Sven Efftinge (AKA Mr. Xtext & Xtend..) at EclipseCon just last week! I've demonstrated the problem, and convinced him that there is one, which is always a good first step.. We attempted a 5' quick fix together (replacement of an ArrayList by a LinkedList), but saw that was no good, and that Xtend lib StringConcatenation would need more than 5' of work. If I have nothing else on my pile, I may spend a bit more time on it, but it's not a high priority for me, given that we have a short-term work around.

Comment by Robert Varga [ 31/Oct/16 ]

yeah, it's maybe 30 minutes – if that protected splitter method can be made non-public If it needs to be retained, you are in a pickle...

Comment by Robert Varga [ 31/Oct/16 ]

Attachment xtextlib.diff has been added with description: prototype dirty fix

Comment by Michael Vorburger [ 01/Nov/16 ]

Robert, as per private email exchange, I've tested your "prototype dirty fix" (above), fixed what we agreed in email was left in there but you meant to remove, and done a few other things in StringConcatenation orthogonal to your change, which in my measurements have an additional measurable positive impact; see https://bugs.opendaylight.org/show_bug.cgi?id=6236 for full details, and https://github.com/eclipse/xtext-lib/pull/16/files for the proposed combined change. It's a step, but somehow I'm not entirely satisfied - still hot spot, when the goal should be to not have any in three.. Please do shout if you see any potential for further improvement?

I've attempted to try out the full scenario from above with this fix, by replacing the x3 xtext/xbase/xtend (except xtend-maven-plugin) 2.9.2 in odlparent with locally built 2.11.0-SNAPSHOT:

An "mvno -o -Pq clean install" in netvirt/vpnservice seems to go from approx. 3:07 down to 2:40, so 27s gained (BTW with a master 2.11.0-SNAPSHOT without changes it's still 3:06; tested).

That's something, and reason enough for me to keep suggesting to Xtend to do something about this, on their side. For us in ODL in the short term though, as even this gain, if they accept it, when we upgrade, is still less than the more significant 1’ gain seen earlier above when just completely skipping Xtend with https://git.opendaylight.org/gerrit/#/c/47036/. My suggestion would thus be that we integrate c/47036 anyway.

PS: When I JMC profile mvn then the hotstop still looks like the old one, so I doubted for a moment whether the lib switch from 2.9.2 to 2.11.0-SNAPSHOT even worked.. but as there is a measurable difference, that must be something else - the most likely explanation I have is that perhaps the test YangTemplateWithoutAnyDependencies.xtend doesn't lead to the exact same result as our "real" YangTemplate.xtend?

Comment by Robert Varga [ 04/Nov/16 ]

Another performance improvement for codegen to not emit empty indentation strings: https://bugs.eclipse.org/bugs/show_bug.cgi?id=507077

Comment by Michael Vorburger [ 12/Nov/16 ]

https://git.opendaylight.org/gerrit/#/c/48290/

Comment by Martin Ciglan [ 02/Dec/16 ]

Hi Michael

I guess this can be closed as RESOLVED FIXED, right?

Comment by Michael Vorburger [ 12/Dec/16 ]

> I guess this can be closed as RESOLVED FIXED, right?

I would suggest to keep it open until a new Xtend version 2.11 including our (Robert's) fixes is released, and then switch to it, and retest.. According to https://typefox.io/xtext-2-11-beta-1-is-here, "The Xtext 2.11 release has been rescheduled for January 24th 2017."

Comment by Robert Varga [ 12/Dec/16 ]

boron backport: https://git.opendaylight.org/gerrit/49234

Comment by Robert Varga [ 12/Dec/16 ]

The rest should be handled by odlparent upgrading to xtend to 2.11 once it is out.

Comment by Michael Vorburger [ 12/Dec/16 ]

> boron backport: https://git.opendaylight.org/gerrit/49234

OK but in that case, also https://git.opendaylight.org/gerrit/#/c/49235/

Comment by Robert Varga [ 22/Dec/16 ]

The workarounds have been delivered to Boron-SR3, upstream patches have been accepted and will be part of xtend-2.11, which is scheduled to release on Jan 24.

Targeting for M4 for the corresponding version bump.

Comment by Robert Varga [ 30/Jan/17 ]

xtext release has been delayed, we will probably not make it to M5.

patch to bump to 2.11.0.RC2: https://git.opendaylight.org/gerrit/51185

Comment by Robert Varga [ 02/Feb/17 ]

final bump: https://git.opendaylight.org/gerrit/51357

Generated at Wed Feb 07 20:27:27 UTC 2024 using Jira 8.20.10#820010-sha1:ace47f9899e9ee25d7157d59aa17ab06aee30d3d.