Adds KeyPath test to benchmark suite#36451
Adds KeyPath test to benchmark suite#36451taylorGeisler wants to merge 5 commits intoswiftlang:mainfrom
Conversation
|
@swift-ci smoke test |
|
@swift-ci benchmark |
Performance: -O
Code size: -OPerformance: -Osize
Code size: -OsizePerformance: -Onone
Code size: -swiftlibs
How to read the dataThe tables contain differences in performance which are larger than 8% and differences in code size which are larger than 1%.If you see any unexpected regressions, you should consider fixing the Noise: Sometimes the performance results (not code size!) contain false Hardware Overview |
eeckstein
left a comment
There was a problem hiding this comment.
The key path accesses are all optimized away. You can use identity to prevent that, e.g.
let kp0 = identity(FixedSizeArray10<Double>.getKeypathToElement(index: 0))
Also, it would be nice to benchmark other key path operations, like: subscripts, getters, setters.
Adds identity function to avoid keypath being optimized away
|
@swift-ci benchmark |
1 similar comment
|
@swift-ci benchmark |
|
Build failed before running benchmark. |
|
@eeckstein Overall I'd like this benchmark to highlight the performance difference between the KeyPath and Direct Access implementations in working with struct properties. Any further suggestions? |
The difference between both benchmarks is not reported in a benchmark run, e.g. on CI. So the only way to see the difference is to compile the benchmarks locally and manually compare both results. You can keep |
|
@swift-ci benchmark |
|
@swift-ci smoke test |
|
@swift-ci benchmark |
Performance: -O
Code size: -OPerformance: -Osize
Code size: -OsizePerformance: -Onone
Code size: -swiftlibs
How to read the dataThe tables contain differences in performance which are larger than 8% and differences in code size which are larger than 1%.If you see any unexpected regressions, you should consider fixing the Noise: Sometimes the performance results (not code size!) contain false Hardware Overview |
|
@taylorGeisler I just saw that you moved the keypath variables out of the function and made them global. That is not good, because accesses to (non-trivial) globals is slow. |
|
My coworker (from the same company that originated this PR) has been working on a more extensive set of keypath benchmarks in #60383, so I believe it is safe to close out this PR in favor of that newer one. |
This pull request adds a test of KeyPaths performance to the benchmark suite. It creates a fixed size array struct and KeyPaths to its properties. It does work inside of a loop by accessing the properties with KeyPaths.