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

More efficient working with headers #289

Merged
merged 1 commit into from
Aug 8, 2023

Conversation

plokhotnyuk
Copy link
Contributor

@plokhotnyuk plokhotnyuk commented Aug 1, 2023

Currently, it is quite expensive in terms of burned CPU and eaten memory bandwidth during parsing, validation
image
...and serialization
image

This PR reduces that overheads and improves working with headers.

@plokhotnyuk plokhotnyuk force-pushed the master branch 2 times, most recently from 95beca0 to 4cfcb69 Compare August 1, 2023 13:40
@plokhotnyuk plokhotnyuk changed the title More efficient working with accepts and media types More efficient working with headers Aug 1, 2023
@plokhotnyuk plokhotnyuk force-pushed the master branch 3 times, most recently from c41793d to a61ea20 Compare August 2, 2023 09:54
@plokhotnyuk
Copy link
Contributor Author

plokhotnyuk commented Aug 2, 2023

@adamw @kciesielski Could you please review and merge this PR?

Would you be interested in subsequent improving working with headers and paths (as example replacing regexp and split calls by more efficient implementations)?

@kciesielski
Copy link
Member

@plokhotnyuk Thank you! Performance improvements like this one are much appreciated, and we are definitely interested in subsequent PRs. Unfortunately, the core code has to compile for Scala 2.12 as well. Could you adjust your changes to this requirement?

@plokhotnyuk
Copy link
Contributor Author

plokhotnyuk commented Aug 7, 2023

@kciesielski Sorry, I had missed to check that sbt +core/test doesn't run tests across Scala versions.

I've force pushed an updated commit with fixes that I had tested locally by the following sequence of commands:

sbt ++2.12.18 core/test
sbt ++2.13.11 core/test
sbt ++3.3.0 core/test

@kciesielski
Copy link
Member

@plokhotnyuk We use the sbt-projectmatrix plugin, which generates dynamic projects for each scala version. The core project is for Scala 2.13, core2_12 for 2.12 and core3 for Scala 3. The failed compilation happens on core2_12/compile (compile scope).

@plokhotnyuk
Copy link
Contributor Author

@kciesielski Thanks, for the heads up! Now core2_12/compile compiles without any errors.

@kciesielski
Copy link
Member

Awesome, thanks again!

@kciesielski kciesielski merged commit 27d9bc3 into softwaremill:master Aug 8, 2023
}
}
private def processString(str: String): List[WeightedEncoding] =
str.trim.split(",").map(x => parsSingleEncoding(x.trim)).reverse.toList // TODO: do we really need `.reverse` here?
Copy link
Member

Choose a reason for hiding this comment

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

regarding the TODO - yeah it looks weird, why would we need to reverse; if anything, we want to preserve the original ordering?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Originally reversing was introduced by recursive version of previous implementation.

So my question in the TODO message was about need of reversion for the result list.

Copy link
Member

Choose a reason for hiding this comment

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

There was another tail-recursion with an accumulator which reversed the list - I moved the reverse to the more logical place: ea43d96

Thanks for the PR, btw :)

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.

3 participants