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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[jvm] Scan classes in parallel #905

Merged
merged 1 commit into from
Jul 30, 2020

Conversation

raniejade
Copy link
Member

//cc @arturbosch

I'll merge this to the 2.0.x branch which will trigger a CI build and publish an artifact to: https://bintray.com/spekframework/spek-dev/

@raniejade raniejade merged commit cecb731 into 2.0.x Jul 30, 2020
@raniejade raniejade deleted the ranie/make-class-scanning-run-in-parallel branch July 30, 2020 10:48
@@ -44,13 +48,15 @@ object JvmDiscoveryContextFactory {
private fun scanClasses(testDirs: List<String>): List<KClass<out Spek>> {
val cg = ClassGraph()
.enableClassInfo()
// any jar on the classpath won't be scanned
.disableJarScanning()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be huge! Thanks

@raniejade
Copy link
Member Author

@arturbosch
Copy link

@arturbosch new build is out https://bintray.com/spekframework/spek-dev/spek2/2.0.13-alpha.0.1%2Bcecb731 can you try it out?

I've updated detekt/detekt#2902 (comment)

This patch decreases the discovery time by 1 second 🎉 . Jupiter still is 1 second faster though.
I will now run build scans for the whole build and keep you updated.

@raniejade
Copy link
Member Author

Ohh, that's good news! I'll see if I can configure classgraph further to scan less.

@arturbosch
Copy link

arturbosch commented Jul 30, 2020

Our full test time without the gradle plugin decreased by ~ 20s from 2m8s to 1m47s!

Is Spek using a lot of concurrency by default? If yes, maybe this could lead to threads starving when used together with gradle --parallel. I know that Jupiter uses opt-in for concurrency.

I see 10seconds discovery time for very simple modules:

With snapshot:
2020-07-30-131741_1191x156_scrot

With 2.0.12:
2020-07-30-131857_1182x66_scrot

@@ -12,6 +12,10 @@ import kotlin.reflect.full.primaryConstructor
import kotlin.streams.toList

object JvmDiscoveryContextFactory {
private val scanParallelism by lazy {
Runtime.getRuntime().availableProcessors()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lazy shouldn't be necessary here?

If I use gradle --parallel with 8 cores this will start 8*8 threads to scan the classpath?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was about to link this, and yeah it probably will. I'm still thinking of a way to make this configurable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It sucks that you can't pass configs from gradle to JUnit Platform test engines.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be sequential by default and be configurable like you did with the timeout property:
systemProperty("SPEK_TIMEOUT", 0) // disable test timeout.
Junit5 itself wants to be configured for concurrency with system properties: https://junit.org/junit5/docs/current/user-guide/#running-tests-build-gradle-config-params

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh that makes sense - I don't have time now, but I'll look into it in the weekend. Thanks!

@raniejade
Copy link
Member Author

I had a closer look, Classgraph is already scanning in parallel by default - so adding disableJarScanning() probably made the biggest difference.

raniejade added a commit that referenced this pull request Aug 6, 2020
(cherry picked from commit cecb731)
raniejade added a commit that referenced this pull request Aug 6, 2020
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 this pull request may close these issues.

None yet

2 participants