Skip to content

Add any and all expression support.#49

Merged
jefferai merged 9 commits intohashicorp:mainfrom
remilapeyre:any-all
Sep 11, 2023
Merged

Add any and all expression support.#49
jefferai merged 9 commits intohashicorp:mainfrom
remilapeyre:any-all

Conversation

@remilapeyre
Copy link
Copy Markdown

The syntax is inspired by Sentinel Any, All Expressions and the For Statements.

Supporting this sort of complex conditions is useful for the Vault SAML auth method.

The syntax is inspired by Sentinel [Any, All Expressions](https://docs.hashicorp.com/sentinel/language/boolexpr#any-all-expressions)
and the [For Statements](https://docs.hashicorp.com/sentinel/language/loops#for-statements).

Supporting this sort of complex conditions is useful for the Vault SAML auth method.
@remilapeyre remilapeyre requested review from a team, dekimsey and jeanneryan and removed request for a team September 6, 2023 01:09
@remilapeyre remilapeyre marked this pull request as draft September 6, 2023 13:57
Comment thread grammar/grammar.peg Outdated
@remilapeyre remilapeyre requested a review from mkeeler September 7, 2023 08:48
@remilapeyre remilapeyre marked this pull request as ready for review September 7, 2023 08:48
@mkeeler
Copy link
Copy Markdown
Member

mkeeler commented Sep 7, 2023

Benchmarks are showing pretty big improvement with the new code.

goos: darwin
goarch: amd64
pkg: github.com/hashicorp/go-bexpr
cpu: Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
                                           │    old.txt    │               new.txt               │
                                           │    sec/op     │    sec/op     vs base               │
Evaluate/Nested_Structs_and_Maps/#0-16        1.227µ ± ∞ ¹   1.109µ ± ∞ ¹   -9.62% (p=0.008 n=5)
Evaluate/Nested_Structs_and_Maps/#1-16        1.714µ ± ∞ ¹   1.555µ ± ∞ ¹   -9.28% (p=0.008 n=5)
Evaluate/Nested_Structs_and_Maps/#2-16        1.802µ ± ∞ ¹   1.606µ ± ∞ ¹  -10.88% (p=0.008 n=5)
Evaluate/Nested_Structs_and_Maps/#3-16        1.830µ ± ∞ ¹   1.620µ ± ∞ ¹  -11.48% (p=0.008 n=5)
Evaluate/Nested_Structs_and_Maps/#4-16       1213.0n ± ∞ ¹   967.3n ± ∞ ¹  -20.26% (p=0.008 n=5)
Evaluate/Nested_Structs_and_Maps/#5-16       1303.0n ± ∞ ¹   972.0n ± ∞ ¹  -25.40% (p=0.008 n=5)
Evaluate/Nested_Structs_and_Maps/#6-16        2.100µ ± ∞ ¹   1.748µ ± ∞ ¹  -16.76% (p=0.008 n=5)
Evaluate/Nested_Structs_and_Maps/#7-16        1.807µ ± ∞ ¹   1.589µ ± ∞ ¹  -12.06% (p=0.016 n=5)
Evaluate/Nested_Structs_and_Maps/#8-16        1.835µ ± ∞ ¹   1.621µ ± ∞ ¹  -11.66% (p=0.008 n=5)
Evaluate/Nested_Structs_and_Maps/#9-16        1.243µ ± ∞ ¹   1.177µ ± ∞ ¹   -5.31% (p=0.016 n=5)
Evaluate/Nested_Structs_and_Maps/#10-16       1.248µ ± ∞ ¹   1.112µ ± ∞ ¹  -10.90% (p=0.008 n=5)
Evaluate/Nested_Structs_and_Maps/#11-16       1.832µ ± ∞ ¹   1.574µ ± ∞ ¹  -14.08% (p=0.008 n=5)
Evaluate/Nested_Structs_and_Maps/#12-16       907.3n ± ∞ ¹   716.4n ± ∞ ¹  -21.04% (p=0.008 n=5)
Evaluate/Nested_Structs_and_Maps/#13-16       3.824µ ± ∞ ¹   3.053µ ± ∞ ¹  -20.16% (p=0.008 n=5)
Evaluate/Nested_Structs_and_Maps/#14-16       1.662µ ± ∞ ¹   1.444µ ± ∞ ¹  -13.12% (p=0.008 n=5)
Evaluate/Nested_Structs_and_Maps/#15-16       1.247µ ± ∞ ¹   1.061µ ± ∞ ¹  -14.92% (p=0.008 n=5)
Evaluate/Nested_Structs_and_Maps/#16-16       1.260µ ± ∞ ¹   1.018µ ± ∞ ¹  -19.21% (p=0.008 n=5)
Evaluate/Nested_Structs_and_Maps/#17-16       3.001µ ± ∞ ¹   2.186µ ± ∞ ¹  -27.16% (p=0.008 n=5)
Evaluate/Nested_Structs_and_Maps/#18-16       1.672µ ± ∞ ¹   1.541µ ± ∞ ¹   -7.83% (p=0.008 n=5)
Evaluate/Nested_Structs_and_Maps/#19-16       1.612µ ± ∞ ¹   1.477µ ± ∞ ¹   -8.37% (p=0.008 n=5)
Evaluate/Nested_Structs_and_Maps/#20-16       1.303µ ± ∞ ¹   1.085µ ± ∞ ¹  -16.73% (p=0.008 n=5)
Evaluate/Nested_Structs_and_Maps/#21-16       1.274µ ± ∞ ¹   1.064µ ± ∞ ¹  -16.48% (p=0.008 n=5)
Evaluate/Nested_Structs_and_Maps/#22-16       1.310µ ± ∞ ¹   1.203µ ± ∞ ¹        ~ (p=0.063 n=5)
Evaluate/Nested_Structs_and_Maps/#23-16       1.481µ ± ∞ ¹   1.255µ ± ∞ ¹  -15.26% (p=0.008 n=5)
Evaluate/Nested_Structs_and_Maps/#24-16       1.461µ ± ∞ ¹   1.228µ ± ∞ ¹  -15.95% (p=0.008 n=5)
Evaluate/Nested_Structs_and_Maps/#25-16       2.012µ ± ∞ ¹   1.873µ ± ∞ ¹   -6.91% (p=0.008 n=5)
Evaluate/Nested_Structs_and_Maps/#26-16       3.174µ ± ∞ ¹   2.811µ ± ∞ ¹  -11.44% (p=0.008 n=5)
Evaluate/Nested_Structs_and_Maps/#27-16       3.250µ ± ∞ ¹   2.811µ ± ∞ ¹  -13.51% (p=0.008 n=5)
Evaluate/Nested_Structs_and_Maps/#28-16       3.239µ ± ∞ ¹   2.864µ ± ∞ ¹  -11.58% (p=0.008 n=5)
Evaluate/Nested_Structs_and_Maps/#29-16       3.320µ ± ∞ ¹   2.819µ ± ∞ ¹  -15.09% (p=0.008 n=5)
Evaluate/Nested_Structs_and_Maps/#30-16       3.270µ ± ∞ ¹   2.850µ ± ∞ ¹  -12.84% (p=0.008 n=5)
Evaluate/Nested_Structs_and_Maps/#31-16       3.193µ ± ∞ ¹   2.795µ ± ∞ ¹  -12.46% (p=0.008 n=5)
Evaluate/Nested_Structs_and_Maps/#32-16       3.136µ ± ∞ ¹   2.812µ ± ∞ ¹  -10.33% (p=0.008 n=5)
Evaluate/Nested_Structs_and_Maps/#33-16       3.172µ ± ∞ ¹   2.879µ ± ∞ ¹   -9.24% (p=0.008 n=5)
Evaluate/Nested_Structs_and_Maps/#34-16       2.588µ ± ∞ ¹   2.201µ ± ∞ ¹  -14.95% (p=0.008 n=5)
Evaluate/Nested_Structs_and_Maps/#35-16       2.607µ ± ∞ ¹   2.192µ ± ∞ ¹  -15.92% (p=0.008 n=5)
Evaluate/Nested_Structs_and_Maps/#36-16       2.646µ ± ∞ ¹   2.211µ ± ∞ ¹  -16.44% (p=0.008 n=5)
Evaluate/Nested_Structs_and_Maps/#37-16       2.683µ ± ∞ ¹   2.210µ ± ∞ ¹  -17.63% (p=0.016 n=5)
Evaluate/Nested_Structs_and_Maps/#38-16       2.595µ ± ∞ ¹   2.216µ ± ∞ ¹  -14.61% (p=0.008 n=5)
Evaluate/Nested_Structs_and_Maps/#39-16       2.584µ ± ∞ ¹   2.192µ ± ∞ ¹  -15.17% (p=0.008 n=5)
Evaluate/Nested_Structs_and_Maps/#40-16       2.639µ ± ∞ ¹   2.187µ ± ∞ ¹  -17.13% (p=0.008 n=5)
Evaluate/Nested_Structs_and_Maps/#41-16       2.617µ ± ∞ ¹   2.265µ ± ∞ ¹  -13.45% (p=0.008 n=5)
Evaluate/Flat_Struct/#0-16                    1.663µ ± ∞ ¹   1.493µ ± ∞ ¹  -10.22% (p=0.008 n=5)
Evaluate/Flat_Struct/#1-16                    1.598µ ± ∞ ¹   1.441µ ± ∞ ¹   -9.82% (p=0.008 n=5)
Evaluate/Flat_Struct/#2-16                    1.606µ ± ∞ ¹   1.450µ ± ∞ ¹   -9.71% (p=0.008 n=5)
Evaluate/Flat_Struct/#3-16                    1.600µ ± ∞ ¹   1.509µ ± ∞ ¹        ~ (p=0.127 n=5)
Evaluate/Flat_Struct/#4-16                    1.572µ ± ∞ ¹   1.431µ ± ∞ ¹   -8.97% (p=0.008 n=5)
Evaluate/Flat_Struct/#5-16                    1.608µ ± ∞ ¹   1.471µ ± ∞ ¹   -8.52% (p=0.008 n=5)
Evaluate/Flat_Struct/#6-16                    1.871µ ± ∞ ¹   1.505µ ± ∞ ¹  -19.56% (p=0.008 n=5)
Evaluate/Flat_Struct/#7-16                    1.736µ ± ∞ ¹   1.514µ ± ∞ ¹  -12.79% (p=0.008 n=5)
Evaluate/Flat_Struct/#8-16                    1.708µ ± ∞ ¹   1.514µ ± ∞ ¹  -11.36% (p=0.008 n=5)
Evaluate/Flat_Struct/#9-16                    1.712µ ± ∞ ¹   1.453µ ± ∞ ¹  -15.13% (p=0.008 n=5)
Evaluate/Flat_Struct/#10-16                   1.692µ ± ∞ ¹   1.546µ ± ∞ ¹        ~ (p=0.056 n=5)
Evaluate/Flat_Struct/#11-16                   1.615µ ± ∞ ¹   1.537µ ± ∞ ¹   -4.83% (p=0.008 n=5)
Evaluate/Flat_Struct/#12-16                   1.780µ ± ∞ ¹   1.513µ ± ∞ ¹  -15.00% (p=0.008 n=5)
Evaluate/Flat_Struct/#13-16                   1.681µ ± ∞ ¹   1.487µ ± ∞ ¹  -11.54% (p=0.008 n=5)
Evaluate/Flat_Struct/#14-16                   1.762µ ± ∞ ¹   1.457µ ± ∞ ¹  -17.31% (p=0.008 n=5)
Evaluate/Flat_Struct/#15-16                   1.839µ ± ∞ ¹   1.488µ ± ∞ ¹  -19.09% (p=0.008 n=5)
Evaluate/Flat_Struct/#16-16                   1.889µ ± ∞ ¹   1.460µ ± ∞ ¹  -22.71% (p=0.008 n=5)
Evaluate/Flat_Struct/#17-16                   1.816µ ± ∞ ¹   1.498µ ± ∞ ¹  -17.51% (p=0.008 n=5)
Evaluate/Flat_Struct/#18-16                   1.808µ ± ∞ ¹   1.447µ ± ∞ ¹  -19.97% (p=0.008 n=5)
Evaluate/Flat_Struct/#19-16                   1.703µ ± ∞ ¹   1.556µ ± ∞ ¹        ~ (p=0.056 n=5)
Evaluate/Flat_Struct/#20-16                   1.714µ ± ∞ ¹   1.477µ ± ∞ ¹  -13.83% (p=0.008 n=5)
Evaluate/Flat_Struct/#21-16                   1.698µ ± ∞ ¹   1.441µ ± ∞ ¹  -15.14% (p=0.008 n=5)
Evaluate/Flat_Struct/#22-16                   1.686µ ± ∞ ¹   1.452µ ± ∞ ¹  -13.88% (p=0.008 n=5)
Evaluate/Flat_Struct/#23-16                   1.695µ ± ∞ ¹   1.466µ ± ∞ ¹  -13.51% (p=0.008 n=5)
Evaluate/Flat_Struct/#24-16                   1.632µ ± ∞ ¹   1.408µ ± ∞ ¹  -13.73% (p=0.008 n=5)
Evaluate/Flat_Struct/#25-16                   1.660µ ± ∞ ¹   1.510µ ± ∞ ¹   -9.04% (p=0.008 n=5)
Evaluate/Flat_Struct/#26-16                   1.702µ ± ∞ ¹   1.416µ ± ∞ ¹  -16.80% (p=0.008 n=5)
Evaluate/Flat_Struct/#27-16                   1.682µ ± ∞ ¹   1.466µ ± ∞ ¹  -12.84% (p=0.008 n=5)
Evaluate/Flat_Struct/#28-16                   1.633µ ± ∞ ¹   1.461µ ± ∞ ¹  -10.53% (p=0.008 n=5)
Evaluate/Flat_Struct/#29-16                   1.672µ ± ∞ ¹   1.492µ ± ∞ ¹  -10.77% (p=0.008 n=5)
Evaluate/Flat_Struct/#30-16                   1.629µ ± ∞ ¹   1.505µ ± ∞ ¹   -7.61% (p=0.008 n=5)
Evaluate/Flat_Struct/#31-16                   1.606µ ± ∞ ¹   1.454µ ± ∞ ¹   -9.46% (p=0.008 n=5)
Evaluate/Flat_Struct/#32-16                   1.694µ ± ∞ ¹   1.414µ ± ∞ ¹  -16.53% (p=0.008 n=5)
Evaluate/Flat_Struct/#33-16                   1.663µ ± ∞ ¹   1.432µ ± ∞ ¹  -13.89% (p=0.008 n=5)
Evaluate/Flat_Struct/#34-16                   1.680µ ± ∞ ¹   1.455µ ± ∞ ¹  -13.39% (p=0.008 n=5)
Evaluate/Flat_Struct/#35-16                   1.718µ ± ∞ ¹   1.465µ ± ∞ ¹  -14.73% (p=0.008 n=5)
Evaluate/Flat_Struct/#36-16                   1.625µ ± ∞ ¹   1.400µ ± ∞ ¹  -13.85% (p=0.008 n=5)
Evaluate/Flat_Struct/#37-16                   1.596µ ± ∞ ¹   1.389µ ± ∞ ¹  -12.97% (p=0.032 n=5)
Evaluate/Flat_Struct/#38-16                   1.629µ ± ∞ ¹   1.399µ ± ∞ ¹  -14.12% (p=0.008 n=5)
Evaluate/Flat_Struct/#39-16                   1.805µ ± ∞ ¹   1.433µ ± ∞ ¹  -20.61% (p=0.008 n=5)
Evaluate/Flat_Struct/#40-16                   1.719µ ± ∞ ¹   1.489µ ± ∞ ¹  -13.38% (p=0.008 n=5)
Evaluate/Flat_Struct/#41-16                   1.725µ ± ∞ ¹   1.494µ ± ∞ ¹  -13.39% (p=0.008 n=5)
Evaluate/Flat_Struct/#42-16                   1.663µ ± ∞ ¹   1.482µ ± ∞ ¹  -10.88% (p=0.016 n=5)
Evaluate/Flat_Struct/#43-16                   1.712µ ± ∞ ¹   1.469µ ± ∞ ¹  -14.19% (p=0.008 n=5)
Evaluate/Flat_Struct/#44-16                   1.729µ ± ∞ ¹   1.416µ ± ∞ ¹  -18.10% (p=0.008 n=5)
Evaluate/Flat_Struct/#45-16                   2.088µ ± ∞ ¹   1.479µ ± ∞ ¹  -29.17% (p=0.008 n=5)
Evaluate/Flat_Struct/#46-16                   1.829µ ± ∞ ¹   1.499µ ± ∞ ¹  -18.04% (p=0.008 n=5)
Evaluate/Flat_Struct/#47-16                   1.795µ ± ∞ ¹   1.510µ ± ∞ ¹  -15.88% (p=0.008 n=5)
Evaluate/Flat_Struct/#48-16                   1.807µ ± ∞ ¹   1.494µ ± ∞ ¹  -17.32% (p=0.008 n=5)
Evaluate/Flat_Struct/#49-16                   1.828µ ± ∞ ¹   1.468µ ± ∞ ¹  -19.69% (p=0.008 n=5)
Evaluate/Flat_Struct/#50-16                   1.632µ ± ∞ ¹   1.471µ ± ∞ ¹   -9.87% (p=0.008 n=5)
Evaluate/Flat_Struct/#51-16                   1.649µ ± ∞ ¹   1.472µ ± ∞ ¹  -10.73% (p=0.016 n=5)
Evaluate/Flat_Struct/#52-16                   1.976µ ± ∞ ¹   1.429µ ± ∞ ¹  -27.68% (p=0.008 n=5)
Evaluate/Flat_Struct/#53-16                   1.860µ ± ∞ ¹   1.592µ ± ∞ ¹  -14.41% (p=0.008 n=5)
Evaluate/Flat_Struct/#54-16                   1.732µ ± ∞ ¹   1.488µ ± ∞ ¹  -14.09% (p=0.008 n=5)
Evaluate/Flat_Struct/#55-16                   1.748µ ± ∞ ¹   1.547µ ± ∞ ¹  -11.50% (p=0.032 n=5)
Evaluate/Flat_Struct/#56-16                   1.643µ ± ∞ ¹   1.606µ ± ∞ ¹        ~ (p=0.310 n=5)
Evaluate/Flat_Struct/#57-16                   1.676µ ± ∞ ¹   1.781µ ± ∞ ¹        ~ (p=0.310 n=5)
Evaluate/Flat_Struct/#58-16                   1.702µ ± ∞ ¹   1.526µ ± ∞ ¹  -10.34% (p=0.008 n=5)
Evaluate/Flat_Struct/#59-16                   1.616µ ± ∞ ¹   1.515µ ± ∞ ¹   -6.25% (p=0.008 n=5)
Evaluate/Flat_Struct/#60-16                   1.583µ ± ∞ ¹   1.514µ ± ∞ ¹        ~ (p=0.095 n=5)
Evaluate/Flat_Struct/#61-16                   1.574µ ± ∞ ¹   1.510µ ± ∞ ¹   -4.07% (p=0.008 n=5)
Evaluate/Flat_Struct/#62-16                   1.640µ ± ∞ ¹   1.444µ ± ∞ ¹  -11.95% (p=0.008 n=5)
Evaluate/Flat_Struct/#63-16                   1.692µ ± ∞ ¹   1.475µ ± ∞ ¹  -12.83% (p=0.008 n=5)
Evaluate/Flat_Struct/#64-16                   1.492µ ± ∞ ¹   1.307µ ± ∞ ¹  -12.40% (p=0.008 n=5)
Evaluate/Flat_Struct/#65-16                   2.703µ ± ∞ ¹   2.532µ ± ∞ ¹        ~ (p=0.056 n=5)
Evaluate/Flat_Struct/#66-16                   2.565µ ± ∞ ¹   2.395µ ± ∞ ¹   -6.63% (p=0.008 n=5)
Evaluate/Flat_Struct/#67-16                   1.897µ ± ∞ ¹   1.715µ ± ∞ ¹   -9.59% (p=0.008 n=5)
Evaluate/Flat_Struct/#68-16                   1.860µ ± ∞ ¹   1.644µ ± ∞ ¹  -11.61% (p=0.008 n=5)
Evaluate/Flat_Struct/#69-16                   1.858µ ± ∞ ¹   1.678µ ± ∞ ¹   -9.69% (p=0.032 n=5)
Evaluate/Flat_Struct/#70-16                   1.876µ ± ∞ ¹   1.830µ ± ∞ ¹        ~ (p=0.690 n=5)
Evaluate/Flat_Struct_Alt_Types/#0-16          1.501µ ± ∞ ¹   1.317µ ± ∞ ¹  -12.26% (p=0.008 n=5)
Evaluate/Flat_Struct_Alt_Types/#1-16          1.464µ ± ∞ ¹   1.338µ ± ∞ ¹   -8.61% (p=0.008 n=5)
Evaluate/Flat_Struct_Alt_Types/#2-16          1.435µ ± ∞ ¹   1.260µ ± ∞ ¹  -12.20% (p=0.008 n=5)
Evaluate/Flat_Struct_Alt_Types/#3-16          1.443µ ± ∞ ¹   1.258µ ± ∞ ¹  -12.82% (p=0.008 n=5)
Evaluate/Flat_Struct_Alt_Types/#4-16          1.602µ ± ∞ ¹   1.303µ ± ∞ ¹  -18.66% (p=0.008 n=5)
Evaluate/Flat_Struct_Alt_Types/#5-16          1.566µ ± ∞ ¹   1.303µ ± ∞ ¹  -16.79% (p=0.008 n=5)
Evaluate/Flat_Struct_Alt_Types/#6-16          1.556µ ± ∞ ¹   1.294µ ± ∞ ¹  -16.84% (p=0.008 n=5)
Evaluate/Flat_Struct_Alt_Types/#7-16          1.540µ ± ∞ ¹   1.288µ ± ∞ ¹  -16.36% (p=0.008 n=5)
Evaluate/Flat_Struct_Alt_Types/#8-16          1.551µ ± ∞ ¹   1.356µ ± ∞ ¹  -12.57% (p=0.008 n=5)
Evaluate/Flat_Struct_Alt_Types/#9-16          1.546µ ± ∞ ¹   1.316µ ± ∞ ¹  -14.88% (p=0.008 n=5)
Evaluate/Flat_Struct_Alt_Types/#10-16         1.602µ ± ∞ ¹   1.305µ ± ∞ ¹  -18.54% (p=0.008 n=5)
Evaluate/Flat_Struct_Alt_Types/#11-16         1.512µ ± ∞ ¹   1.295µ ± ∞ ¹  -14.35% (p=0.008 n=5)
Evaluate/Flat_Struct_Alt_Types/#12-16         1.549µ ± ∞ ¹   1.288µ ± ∞ ¹  -16.85% (p=0.008 n=5)
Evaluate/Flat_Struct_Alt_Types/#13-16         1.516µ ± ∞ ¹   1.364µ ± ∞ ¹  -10.03% (p=0.016 n=5)
Evaluate/Flat_Struct_Alt_Types/#14-16         1.562µ ± ∞ ¹   1.359µ ± ∞ ¹  -13.00% (p=0.016 n=5)
Evaluate/Flat_Struct_Alt_Types/#15-16         1.472µ ± ∞ ¹   1.340µ ± ∞ ¹   -8.97% (p=0.008 n=5)
Evaluate/Flat_Struct_Alt_Types/#16-16         1.543µ ± ∞ ¹   1.358µ ± ∞ ¹  -11.99% (p=0.008 n=5)
Evaluate/Flat_Struct_Alt_Types/#17-16         1.583µ ± ∞ ¹   1.420µ ± ∞ ¹  -10.30% (p=0.008 n=5)
Evaluate/Flat_Struct_Alt_Types/#18-16         1.533µ ± ∞ ¹   1.368µ ± ∞ ¹  -10.76% (p=0.008 n=5)
Evaluate/Flat_Struct_Alt_Types/#19-16         1.526µ ± ∞ ¹   1.349µ ± ∞ ¹  -11.60% (p=0.008 n=5)
Evaluate/Flat_Struct_Alt_Types/#20-16         1.481µ ± ∞ ¹   1.348µ ± ∞ ¹   -8.98% (p=0.008 n=5)
Evaluate/Flat_Struct_Alt_Types/#21-16         1.477µ ± ∞ ¹   1.338µ ± ∞ ¹   -9.41% (p=0.016 n=5)
Evaluate/Flat_Struct_Alt_Types/#22-16         1.481µ ± ∞ ¹   1.253µ ± ∞ ¹  -15.40% (p=0.008 n=5)
Evaluate/Flat_Struct_Alt_Types/#23-16         1.551µ ± ∞ ¹   1.254µ ± ∞ ¹  -19.15% (p=0.008 n=5)
Evaluate/Flat_Struct_Alt_Types/#24-16         1.598µ ± ∞ ¹   1.384µ ± ∞ ¹  -13.39% (p=0.008 n=5)
Evaluate/Flat_Struct_Alt_Types/#25-16         1.579µ ± ∞ ¹   1.475µ ± ∞ ¹   -6.59% (p=0.016 n=5)
Evaluate/Flat_Struct_Alt_Types/#26-16         1.609µ ± ∞ ¹   1.401µ ± ∞ ¹  -12.93% (p=0.008 n=5)
Evaluate/Flat_Struct_Alt_Types/#27-16         1.581µ ± ∞ ¹   1.405µ ± ∞ ¹  -11.13% (p=0.008 n=5)
Evaluate/Flat_Struct_Alt_Types/#28-16         1.489µ ± ∞ ¹   1.294µ ± ∞ ¹  -13.10% (p=0.008 n=5)
Evaluate/Flat_Struct_Alt_Types/#29-16         1.616µ ± ∞ ¹   1.294µ ± ∞ ¹  -19.93% (p=0.008 n=5)
Evaluate/Flat_Struct_Alt_Types/#30-16         1.536µ ± ∞ ¹   1.266µ ± ∞ ¹  -17.58% (p=0.008 n=5)
Evaluate/Flat_Struct_Alt_Types/#31-16         1.529µ ± ∞ ¹   1.308µ ± ∞ ¹  -14.45% (p=0.008 n=5)
Evaluate/Flat_Struct_Alt_Types/#32-16         1.568µ ± ∞ ¹   1.322µ ± ∞ ¹  -15.69% (p=0.008 n=5)
Evaluate/Flat_Struct_Alt_Types/#33-16         1.568µ ± ∞ ¹   1.381µ ± ∞ ¹  -11.93% (p=0.008 n=5)
Evaluate/Flat_Struct_Alt_Types/#34-16         1.563µ ± ∞ ¹   1.299µ ± ∞ ¹  -16.89% (p=0.008 n=5)
Evaluate/Flat_Struct_Alt_Types/#35-16         1.602µ ± ∞ ¹   1.327µ ± ∞ ¹  -17.17% (p=0.008 n=5)
Evaluate/Flat_Struct_Alt_Types/#36-16         1.530µ ± ∞ ¹   1.412µ ± ∞ ¹   -7.71% (p=0.008 n=5)
Evaluate/Flat_Struct_Alt_Types/#37-16         1.557µ ± ∞ ¹   1.340µ ± ∞ ¹  -13.94% (p=0.008 n=5)
Evaluate/Flat_Struct_Alt_Types/#38-16         1.563µ ± ∞ ¹   1.483µ ± ∞ ¹   -5.12% (p=0.008 n=5)
Evaluate/Flat_Struct_Alt_Types/#39-16         1.588µ ± ∞ ¹   1.352µ ± ∞ ¹  -14.86% (p=0.008 n=5)
Evaluate/Flat_Struct_Alt_Types/#40-16         1.568µ ± ∞ ¹   1.331µ ± ∞ ¹  -15.11% (p=0.008 n=5)
Evaluate/Flat_Struct_Alt_Types/#41-16         1.580µ ± ∞ ¹   1.336µ ± ∞ ¹  -15.44% (p=0.008 n=5)
Evaluate/Flat_Struct_Alt_Types/#42-16         1.536µ ± ∞ ¹   1.350µ ± ∞ ¹  -12.11% (p=0.008 n=5)
Evaluate/Flat_Struct_Alt_Types/#43-16         1.570µ ± ∞ ¹   1.311µ ± ∞ ¹  -16.50% (p=0.008 n=5)
Evaluate/Flat_Struct_Alt_Types/#44-16         1.542µ ± ∞ ¹   1.324µ ± ∞ ¹  -14.14% (p=0.008 n=5)
Evaluate/Flat_Struct_Alt_Types/#45-16         1.534µ ± ∞ ¹   1.351µ ± ∞ ¹  -11.93% (p=0.008 n=5)
Evaluate/Flat_Struct_Alt_Types/#46-16         1.558µ ± ∞ ¹   1.317µ ± ∞ ¹  -15.47% (p=0.008 n=5)
Evaluate/Flat_Struct_Alt_Types/#47-16         1.540µ ± ∞ ¹   1.343µ ± ∞ ¹  -12.79% (p=0.008 n=5)
Evaluate/Flat_Struct_Alt_Types/#48-16         1.480µ ± ∞ ¹   1.276µ ± ∞ ¹  -13.78% (p=0.008 n=5)
Evaluate/Flat_Struct_Alt_Types/#49-16         1.515µ ± ∞ ¹   1.271µ ± ∞ ¹  -16.11% (p=0.008 n=5)
Evaluate/Flat_Struct_Alt_Types/#50-16         1.495µ ± ∞ ¹   1.279µ ± ∞ ¹  -14.45% (p=0.008 n=5)
Evaluate/Flat_Struct_Alt_Types/#51-16         1.423µ ± ∞ ¹   1.286µ ± ∞ ¹   -9.63% (p=0.008 n=5)
Evaluate/Flat_Struct_Alt_Types/#52-16         1.502µ ± ∞ ¹   1.375µ ± ∞ ¹   -8.46% (p=0.008 n=5)
Evaluate/Flat_Struct_Alt_Types/#53-16         1.469µ ± ∞ ¹   1.295µ ± ∞ ¹  -11.84% (p=0.008 n=5)
Evaluate/Flat_Struct_Alt_Types/#54-16         1.617µ ± ∞ ¹   1.367µ ± ∞ ¹  -15.46% (p=0.008 n=5)
Evaluate/Flat_Struct_Alt_Types/#55-16         1.553µ ± ∞ ¹   1.353µ ± ∞ ¹  -12.88% (p=0.008 n=5)
Evaluate/Flat_Struct_Alt_Types/#56-16         2.560µ ± ∞ ¹   2.464µ ± ∞ ¹   -3.75% (p=0.048 n=5)
Evaluate/Flat_Struct_Alt_Types/#57-16         2.418µ ± ∞ ¹   2.363µ ± ∞ ¹        ~ (p=0.841 n=5)
Evaluate/map[string]map[string]bool/#0-16     1.128µ ± ∞ ¹   1.027µ ± ∞ ¹   -8.95% (p=0.008 n=5)
Evaluate/map[string]map[string]bool/#1-16     1.244µ ± ∞ ¹   1.009µ ± ∞ ¹  -18.89% (p=0.008 n=5)
Evaluate/map[string]map[string]bool/#2-16    1253.0n ± ∞ ¹   991.1n ± ∞ ¹  -20.90% (p=0.008 n=5)
Evaluate/map[string]map[string]bool/#3-16    1191.0n ± ∞ ¹   978.7n ± ∞ ¹  -17.83% (p=0.008 n=5)
Evaluate/map[string]map[string]bool/#4-16     1.222µ ± ∞ ¹   1.084µ ± ∞ ¹  -11.29% (p=0.008 n=5)
Evaluate/map[string]map[string]bool/#5-16     1.256µ ± ∞ ¹   1.046µ ± ∞ ¹  -16.72% (p=0.008 n=5)
Evaluate/map[string]map[string]bool/#6-16    1079.0n ± ∞ ¹   927.1n ± ∞ ¹  -14.08% (p=0.008 n=5)
Evaluate/map[string]map[string]bool/#7-16    1108.0n ± ∞ ¹   914.7n ± ∞ ¹  -17.45% (p=0.008 n=5)
Evaluate/map[string]map[string]bool/#8-16    1119.0n ± ∞ ¹   894.8n ± ∞ ¹  -20.04% (p=0.008 n=5)
Evaluate/map[string]map[string]bool/#9-16    1106.0n ± ∞ ¹   902.4n ± ∞ ¹  -18.41% (p=0.008 n=5)
Evaluate/map[string]map[string]bool/#10-16   1146.0n ± ∞ ¹   935.5n ± ∞ ¹  -18.37% (p=0.008 n=5)
Evaluate/map[string]map[string]bool/#11-16   1178.0n ± ∞ ¹   950.9n ± ∞ ¹  -19.28% (p=0.008 n=5)
Evaluate/map[string]map[string]bool/#12-16    1.420µ ± ∞ ¹   1.220µ ± ∞ ¹  -14.08% (p=0.008 n=5)
Evaluate/map[string]map[string]bool/#13-16    1.406µ ± ∞ ¹   1.218µ ± ∞ ¹  -13.37% (p=0.008 n=5)
Evaluate/map[string]map[string]bool/#14-16    1.480µ ± ∞ ¹   1.224µ ± ∞ ¹  -17.30% (p=0.008 n=5)
Evaluate/map[string]map[string]bool/#15-16    1.411µ ± ∞ ¹   1.238µ ± ∞ ¹  -12.26% (p=0.008 n=5)
Evaluate/map[string]map[string]bool/#16-16    1.395µ ± ∞ ¹   1.220µ ± ∞ ¹  -12.54% (p=0.008 n=5)
Evaluate/map[string]map[string]bool/#17-16    1.428µ ± ∞ ¹   1.344µ ± ∞ ¹   -5.88% (p=0.008 n=5)
Evaluate/map[string]map[string]bool/#18-16    1.568µ ± ∞ ¹   1.251µ ± ∞ ¹  -20.22% (p=0.008 n=5)
Evaluate/map[string]map[string]bool/#19-16    1.566µ ± ∞ ¹   1.240µ ± ∞ ¹  -20.82% (p=0.008 n=5)
Evaluate/map[string]map[string]bool/#20-16    2.322µ ± ∞ ¹   2.385µ ± ∞ ¹        ~ (p=0.333 n=5)
Filter/Slice-16                               3.187µ ± ∞ ¹   2.416µ ± ∞ ¹  -24.19% (p=0.008 n=5)
Filter/Array-16                               3.130µ ± ∞ ¹   2.386µ ± ∞ ¹  -23.77% (p=0.008 n=5)
Filter/Map-16                                 3.808µ ± ∞ ¹   3.144µ ± ∞ ¹  -17.44% (p=0.008 n=5)
Evaluate/Nested_Structs_and_Maps/#42-16                      4.790µ ± ∞ ¹
Evaluate/Nested_Structs_and_Maps/#43-16                      4.243µ ± ∞ ¹
Evaluate/Nested_Structs_and_Maps/#44-16                      2.310µ ± ∞ ¹
Evaluate/Nested_Structs_and_Maps/#45-16                      2.134µ ± ∞ ¹
Evaluate/Nested_Structs_and_Maps/#46-16                      5.278µ ± ∞ ¹
Evaluate/Nested_Structs_and_Maps/#47-16                      6.056µ ± ∞ ¹
Evaluate/Nested_Structs_and_Maps/#48-16                      3.309µ ± ∞ ¹
Evaluate/Nested_Structs_and_Maps/#49-16                      5.290µ ± ∞ ¹
Evaluate/Nested_Structs_and_Maps/#50-16                      6.769µ ± ∞ ¹
Evaluate/Nested_Structs_and_Maps/#51-16                      857.5n ± ∞ ¹
Evaluate/Nested_Structs_and_Maps/#52-16                      1.765µ ± ∞ ¹
Evaluate/Nested_Structs_and_Maps/#53-16                      4.321µ ± ∞ ¹
Evaluate/Nested_Structs_and_Maps/#54-16                      2.133µ ± ∞ ¹
Evaluate/Nested_Structs_and_Maps/#55-16                      3.368µ ± ∞ ¹
Evaluate/Nested_Structs_and_Maps/#56-16                      5.416µ ± ∞ ¹
Evaluate/Nested_Structs_and_Maps/#57-16                      4.159µ ± ∞ ¹
geomean                                       1.698µ         1.566µ        -13.56%
¹ need >= 6 samples for confidence interval at level 0.95

Copy link
Copy Markdown
Member

@mkeeler mkeeler left a comment

Choose a reason for hiding this comment

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

I left a few very minor requests but overall this is looking great.

Comment thread evaluate_test.go
Comment thread evaluate.go
Comment thread evaluate.go Outdated
@remilapeyre
Copy link
Copy Markdown
Author

Here's the results I got for the benchmarks on a m6i.large EC2 instance with make bench BENCHTIME=5s BENCHFULL_ARG="-count=10 -timeout 60m":

goos: linux
goarch: amd64
pkg: github.com/hashicorp/go-bexpr
cpu: Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz
                                          │  main.txt   │              any.txt               │
                                          │   sec/op    │   sec/op     vs base               │
Evaluate/Flat_Struct_Alt_Types/#0-2         1.501µ ± 0%   1.500µ ± 0%       ~ (p=0.565 n=10)
Evaluate/Flat_Struct_Alt_Types/#1-2         1.501µ ± 0%   1.501µ ± 1%       ~ (p=0.612 n=10)
Evaluate/Flat_Struct_Alt_Types/#38-2        1.510µ ± 0%   1.524µ ± 0%  +0.89% (p=0.000 n=10)
Evaluate/Flat_Struct_Alt_Types/#39-2        1.510µ ± 0%   1.523µ ± 0%  +0.86% (p=0.001 n=10)
Evaluate/Flat_Struct_Alt_Types/#46-2        1.520µ ± 0%   1.526µ ± 0%  +0.39% (p=0.001 n=10)
Evaluate/Flat_Struct_Alt_Types/#47-2        1.519µ ± 0%   1.529µ ± 0%  +0.63% (p=0.000 n=10)
Evaluate/Flat_Struct_Alt_Types/#52-2        1.527µ ± 0%   1.540µ ± 0%  +0.85% (p=0.001 n=10)
Evaluate/Flat_Struct_Alt_Types/#53-2        1.524µ ± 0%   1.534µ ± 0%  +0.69% (p=0.000 n=10)
Evaluate/map[string]map[string]bool/#10-2   1.151µ ± 0%   1.140µ ± 0%  -0.91% (p=0.001 n=10)
Evaluate/map[string]map[string]bool/#15-2   1.442µ ± 0%   1.441µ ± 0%       ~ (p=0.393 n=10)
Evaluate/Nested_Structs_and_Maps/#0-2       1.260µ ± 0%   1.274µ ± 0%  +1.11% (p=0.000 n=10)
Evaluate/Nested_Structs_and_Maps/#1-2       1.839µ ± 0%   1.826µ ± 0%  -0.68% (p=0.000 n=10)
Evaluate/Nested_Structs_and_Maps/#2-2       1.847µ ± 0%   1.834µ ± 0%  -0.68% (p=0.001 n=10)
Evaluate/Nested_Structs_and_Maps/#6-2       2.098µ ± 0%   2.109µ ± 1%  +0.52% (p=0.030 n=10)
Evaluate/Nested_Structs_and_Maps/#11-2      1.854µ ± 0%   1.840µ ± 0%  -0.76% (p=0.001 n=10)
Evaluate/Nested_Structs_and_Maps/#13-2      3.927µ ± 0%   3.923µ ± 1%       ~ (p=0.470 n=10)
Evaluate/Nested_Structs_and_Maps/#17-2      2.870µ ± 0%   2.867µ ± 0%  -0.14% (p=0.033 n=10)
Evaluate/Flat_Struct/#0-2                   1.658µ ± 0%   1.653µ ± 0%  -0.33% (p=0.005 n=10)
Evaluate/Flat_Struct/#2-2                   1.661µ ± 0%   1.657µ ± 0%       ~ (p=0.078 n=10)
Evaluate/Flat_Struct/#39-2                  1.667µ ± 0%   1.668µ ± 0%       ~ (p=0.574 n=10)
Evaluate/Flat_Struct/#40-2                  1.669µ ± 0%   1.668µ ± 0%       ~ (p=0.557 n=10)
Evaluate/Flat_Struct/#47-2                  1.677µ ± 0%   1.678µ ± 0%       ~ (p=0.320 n=10)
Evaluate/Flat_Struct/#48-2                  1.677µ ± 0%   1.679µ ± 0%       ~ (p=0.153 n=10)
Evaluate/Flat_Struct/#53-2                  1.692µ ± 0%   1.698µ ± 0%  +0.35% (p=0.001 n=10)
Evaluate/Flat_Struct/#54-2                  1.687µ ± 0%   1.690µ ± 0%       ~ (p=0.180 n=10)
Evaluate/Flat_Struct/#58-2                  1.696µ ± 0%   1.699µ ± 0%       ~ (p=0.053 n=10)
Evaluate/Flat_Struct/#67-2                  2.003µ ± 0%   2.013µ ± 0%  +0.50% (p=0.000 n=10)
Evaluate/Flat_Struct/#68-2                  1.897µ ± 0%   1.908µ ± 0%  +0.61% (p=0.000 n=10)
Filter/Slice-2                              3.406µ ± 0%   3.399µ ± 0%       ~ (p=0.101 n=10)
Filter/Array-2                              3.275µ ± 0%   3.267µ ± 0%  -0.23% (p=0.001 n=10)
Filter/Map-2                                3.956µ ± 1%   3.938µ ± 0%  -0.43% (p=0.001 n=10)
geomean                                     1.835µ        1.837µ       +0.10%

pkg: github.com/hashicorp/go-bexpr/grammar
                                          │  main.txt   │              any.txt               │
                                          │   sec/op    │   sec/op     vs base               │
ExpressionParsing/Contains-2                34.29µ ± 0%   34.01µ ± 0%  -0.80% (p=0.001 n=10)
ExpressionParsing/Is_Not_Empty-2            40.50µ ± 0%   40.14µ ± 0%  -0.89% (p=0.000 n=10)
ExpressionParsing/In_And_Not_Equals-2       59.83µ ± 0%   59.11µ ± 0%  -1.20% (p=0.000 n=10)
ExpressionParsing/Many_Ors-2                116.6µ ± 0%   114.7µ ± 0%  -1.68% (p=0.000 n=10)
ExpressionParsing/Lots_of_Parens-2          22.83m ± 0%   22.25m ± 0%  -2.54% (p=0.000 n=10)
ExpressionParsing/Not_Equals-2              28.99µ ± 0%   28.81µ ± 0%  -0.63% (p=0.001 n=10)
ExpressionParsing/In-2                      55.74µ ± 0%   55.17µ ± 0%  -1.02% (p=0.000 n=10)
ExpressionParsing/Not_Matches-2             37.96µ ± 0%   37.64µ ± 0%  -0.83% (p=0.001 n=10)
ExpressionParsing/Not_Contains-2            34.22µ ± 0%   33.94µ ± 0%  -0.83% (p=0.000 n=10)
ExpressionParsing/Not_In_Or_Equals-2        60.97µ ± 0%   61.77µ ± 1%  +1.32% (p=0.002 n=10)
ExpressionParsing/Big_Selectors-2           87.84µ ± 0%   89.31µ ± 1%  +1.68% (p=0.000 n=10)
ExpressionParsing/Equals-2                  27.44µ ± 0%   27.29µ ± 0%  -0.53% (p=0.000 n=10)
ExpressionParsing/Is_Empty-2                36.85µ ± 0%   36.51µ ± 0%  -0.93% (p=0.000 n=10)
ExpressionParsing/Matches-2                 34.41µ ± 0%   34.23µ ± 0%  -0.53% (p=0.000 n=10)
ExpressionParsing/Lots_of_Ops-2             132.7µ ± 0%   130.7µ ± 0%  -1.50% (p=0.000 n=10)
ExpressionParsing/Not_In-2                  59.75µ ± 0%   59.95µ ± 1%       ~ (p=0.393 n=10)
ExpressionParsing/Not_Equals_And_Equals-2   152.1µ ± 0%   149.6µ ± 0%  -1.65% (p=0.000 n=10)
geomean                                     76.46µ        75.91µ       -0.72%

@remilapeyre remilapeyre requested a review from mkeeler September 7, 2023 21:07
Comment thread evaluate.go
}

func evaluateMatchExpression(expression *grammar.MatchExpression, datum interface{}, opt ...Option) (bool, error) {
func getValue(datum interface{}, path []string, opt ...Option) (interface{}, bool, error) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It'd be nice to have a comment here just detailing what this function is doing (the overall flow with the local variables).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks, I added some comments now.

Comment thread evaluate.go Outdated
Comment thread evaluate.go Outdated
@remilapeyre remilapeyre requested a review from jefferai September 8, 2023 09:13
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