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

Optimize Coroutine invocations #32390

Closed
sdeleuze opened this issue Mar 7, 2024 · 6 comments
Closed

Optimize Coroutine invocations #32390

sdeleuze opened this issue Mar 7, 2024 · 6 comments
Assignees
Labels
theme: kotlin An issue related to Kotlin support type: enhancement A general enhancement
Milestone

Comments

@sdeleuze
Copy link
Contributor

sdeleuze commented Mar 7, 2024

KClass instantiation in CoroutinesUtils is suboptimal, and should be replaced by KTypes#isSubtypeOf checks using pre-instantiated types for Flow, Mono and Publisher.

@sdeleuze sdeleuze added type: enhancement A general enhancement theme: kotlin An issue related to Kotlin support labels Mar 7, 2024
@sdeleuze sdeleuze added this to the 6.1.5 milestone Mar 7, 2024
@sdeleuze sdeleuze self-assigned this Mar 7, 2024
@sdeleuze
Copy link
Contributor Author

sdeleuze commented Mar 7, 2024

This commit impact on performances is significant since a throughput increase between 2x and 3x has been measured on basic endpoints.

@sdeleuze
Copy link
Contributor Author

sdeleuze commented Mar 7, 2024

@koo-taejin @efemoney Please test the latest 6.1.5-SNAPSHOT builds and report if you see some unexpected side effects.

@efemoney
Copy link

Tested from my side & passes all my tests 👍🏾 just like the previous snapshot

@koo-taejin
Copy link
Contributor

I am going to test it. 👍 thanks :)

@koo-taejin
Copy link
Contributor

Unfortunately, I don't think the situation has changed much.
It would be accurate to put it into production and test it, but I apologize for not being able to do this.

Method of getClassifier() has been replaced by method of getJvmErasure().
I had checked that getClassifier() is called from getJvmErasure().
(in org.springframework.core.CoroutinesUtils.lambda$invokeSuspendingFunction$2(Object[], KFunction, Object, CoroutineScope, Continuation))

  • spring-boot 3.2.0
    image

  • spring-boot 3.2.1 with 6.1.5-SNAPSHOT-p1
    image

  • spring-boot 3.2.1 with 6.1.5-SNAPSHOT-p2
    image

Also, in the latest version, the isSubTypeOf() method uses resources.
(in org.springframework.core.CoroutinesUtils#invokeSuspendingFunction(kotlin.coroutines.CoroutineContext, java.lang.reflect.Method, java.lang.Object, java.lang.Object...))

  • spring-boot 3.2.1 with 6.1.5-SNAPSHOT-p1
    image

  • spring-boot 3.2.1 with 6.1.5-SNAPSHOT-p2
    image

This is called for every suspend function, so more use Coroutines, the bigger the impact seems to be.

If there is anything I can do to help, please let me know.

Thank you so much. 🙇

@sdeleuze
Copy link
Contributor Author

See this related comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: kotlin An issue related to Kotlin support type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants