Skip to content

Conversation

diegommm
Copy link
Contributor

@diegommm diegommm commented Sep 27, 2025

Fix #839

We keep using nature.Nature instead of *nature.Nature inside of ast.base because this reduces the number of checks and makes the implementation safer. Also, we always assume that we will have a nature, and the zero value of a nature is also useful, so no need to ever return nil.

@antonmedv this actually resulted in a minor performance improvement in several places and it also makes code more readable as you suggested 😃

Checker benchmarks
goos: linux
goarch: amd64
pkg: github.com/expr-lang/expr/checker
cpu: 13th Gen Intel(R) Core(TM) i7-13700Hbench-results-old.txtbench-results-stable.txt      │
                                            │        sec/opsec/op     vs baseChecker/name=function_calls-20                          4.658µ ± 3%   4.620µ ± 2%       ~ (p=0.218 n=10)
Checker/name=unary_and_binary_operations-20             4.512µ ± 2%   4.502µ ± 1%       ~ (p=0.697 n=10)
Checker/name=deep_struct_access-20                      12.31µ ± 1%   12.17µ ± 1%  -1.11% (p=0.002 n=10)
geomean                                                 6.371µ        6.326µ       -0.71%bench-results-old.txtbench-results-stable.txt       │
                                            │         B/opB/op     vs baseChecker/name=function_calls-20                         0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
Checker/name=unary_and_binary_operations-20            0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
Checker/name=deep_struct_access-20                     0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
geomean                                                           ²               +0.00%                ²
¹ all samples are equal
² summaries must be >0 to compute geomeanbench-results-old.txtbench-results-stable.txt       │
                                            │       allocs/opallocs/op   vs baseChecker/name=function_calls-20                         0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
Checker/name=unary_and_binary_operations-20            0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
Checker/name=deep_struct_access-20                     0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
geomean                                                           ²               +0.00%                ²
¹ all samples are equal
² summaries must be >0 to compute geomean

@diegommm diegommm marked this pull request as draft September 27, 2025 21:50
@diegommm diegommm marked this pull request as ready for review September 27, 2025 22:07
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.

Pointer reference to nature
1 participant