chore(perf): optimise tm_alltrue() and tm_anytrue().#1282
Open
Conversation
|
fd2a9b0 to
46848f3
Compare
Signed-off-by: Tiago Natel <t.nateldemoura@gmail.com>
46848f3 to
a819810
Compare
✅ Deploy Preview for docs-terramate-io canceled.
|
Contributor
really well done @i4ki |
…mate into i4k-optimize-tm-alltrue
…mate into i4k-optimize-tm-alltrue
Signed-off-by: i4k <t.nateldemoura@gmail.com>
|
Preview of ubuntu-focal/go1.21 tests in cf4a062🔍 View Details on Terramate Cloud globals
stdlib
|
… i4k-optimize-tm-alltrue
Preview of macos-ventura/go1.21 tests in cf4a062🔍 View Details on Terramate Cloud globals
stdlib
|
zied-elouaer
previously approved these changes
Oct 24, 2024
snakster
previously approved these changes
Oct 24, 2024
The base branch was changed.
Contributor
|
@i4ki can this be merged? |
Contributor
Author
|
The last consensus was that the behavior change was desirable. I will revamp this PR and make it r4r again. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does / why we need it:
PROPOSAL: This PR optimises
tm_alltrue()andtm_anytruebut introduces a non-breaking behavior change that could be undesirable, so it requires discussion.It optimises the
tm_alltrue()andtm_anytrue()by lazy evaluating the function's arguments using thecustomdecode.ExpressionClosureTypeand then only evaluating the needed argument elements as below:For
tm_alltrue()the function returns as soon as afalseelement is found.For
tm_anytrue()the function returns as soon as atrueelement is found.Benchmark results:
The
TmAllTrueLiteralList*benchmark tests the case where expensive expressions are provided in the function arguments, then the expensive part is not evaluated, that's why the huge performance win.Which issue(s) this PR fixes:
Special notes for your reviewer:
This implementation does not match 100% the original, see below:
Does this PR introduce a user-facing change?
Checklist