Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Lazy string interpolation in ENSURE #2454

Conversation

alexbereznikov
Copy link

String interpolation on hot paths leads to performance degradation. We need these messages only when error happened.
With #2453 applied this gives 3x performance boost.

This partially fixes #2451

@ltetak
Copy link
Contributor

ltetak commented Mar 26, 2024

Good catch. I guess it would be more standard to move the string interpolation deeper as other libraries do it.
public static void ENSURE(bool conditional, string message, params object[] args)

@alexbereznikov
Copy link
Author

@ltetak Sure I thought about that, but profiling says that most of the time was lost in BasePage.ToString() and I'm not quite sure how to avoid calculating it when passing via args

@alexbereznikov
Copy link
Author

@ltetak Actually this .ToString() call is redundant as formatter will call it either way. So it should work in the way you proposed, pushed fixed code, please take a look

@ltetak
Copy link
Contributor

ltetak commented Mar 27, 2024

@alexbereznikov I am not an owner of this repo. But this looks like a great performance improvement without any risks or side effects.
cc: @mbdavid

@JKamsker JKamsker merged commit a08e330 into litedb-org:master Jun 4, 2024
1 check passed
@JKamsker
Copy link
Collaborator

JKamsker commented Jun 4, 2024

LGTM! Thanks for your contribution!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Performance degradation in v5.0.18
3 participants