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

optimization: cache ClassTag[Token] to avoid thread blocking #308

Merged
merged 1 commit into from
Oct 15, 2023

Conversation

fwbrasil
Copy link
Contributor

Problem

I'm working on a Tapir module for Kyo and noticed that there's some thread blocking to materialize ClassTags in UriInterpolator. It seems a mild problem that should affect mostly benchmarks but there could be pathological scenarios with more complex routing that make it more problematic:

sttp-baseline

Solution

Cache the ClassTag in a local field to avoid the synchronized cache lookup. The change avoids the blocking in UriInterpolator but there are still other cases that arise from other collection operations:

sttp-optimized

Notes

  • As an alternative users could disable the ClassTag cache via -Dscala.reflect.classtag.cache.disable=true but it could have a performance penalty.
  • If there's an interest, I could explore ways to avoid the remaining sources of blocking.

@adamw
Copy link
Member

adamw commented Oct 15, 2023

If there's an interest, I could explore ways to avoid the remaining sources of blocking.

Of course, we're always open to PRs, and performance improvements in particular :)

@fwbrasil
Copy link
Contributor Author

Of course, we're always open to PRs, and performance improvements in particular :)

Great! Do you have benchmarks you normally use to validate Tapir's performance?

@adamw
Copy link
Member

adamw commented Oct 15, 2023

@fwbrasil we do have some very basic tests, comparing "vanilla" akkahttp/http4s servers vs the same servers, but with tapir added on top, to check the overhead that tapir imposes. However, running them is not part of CI or the release process: https://github.com/softwaremill/tapir/tree/master/perf-tests

@adamw adamw merged commit 46c860a into softwaremill:master Oct 15, 2023
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.

2 participants