-
Notifications
You must be signed in to change notification settings - Fork 176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Few benchmarks for predicate evaluation #291
Few benchmarks for predicate evaluation #291
Conversation
…e from the package-data-model.
…on-functionality-instead
fix(patch): [sc-3840] Refer branch instead of commit hash.
…ndation-functionality-instead fix(patch): [sc-3840] Refer dependencies using branches to avoid SPM complaining.
…ndation-functionality-instead-2 fix(patch): Rename ordo/swift-foundation to ordo/package-swift-foundation.
…ndation-functionality-instead-3 Bump dependency version.
…ndation-functionality-instead-4 fix(patch): Bump dependency version
…ndation-functionality-instead-5 Bump dependency version.
…ft-foundation into feature/predicate-benchmark
@ser-0xff I think the test needs to use existentials as we do for transactions internally, the current benchmark does not show the same key path problem we see with a protocol type wrapper. |
Alright, let me look into. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM now, thanks for the rework!
Add standard project header
@swift-ci please test |
Thanks again for posting this, this looks super exciting and will definitely help us expand on our performance testing of this package going forward. We're still looking into this and will get back to you on being able to merge this soon! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall this looks great, thanks for posting this! A few comments about some various pieces, but I'm looking forward to being able to land this so we can start building up our benchmarking suite to measure performance of this package
Addressed PR feedback in 80a84c3 - also added ARC output by default (even though some implicit retains are not necessarily counted currently as some hooks in the runtime are missing, see swiftlang/swift#64636 - it's still useful to see the relative usage of ARC traffic between different test scenarios even if retain/releases doesn't square out exactly.) Current output (throughput is in K):
|
…le check for macOS 14
… tests (the test number is mostly useful for filtering with --filter when wanting to run a specific test)
…r for manual workflows, e.g. swift package benchmark --filter predicateKeypathPropertyCondition
Ok, simplified the naming of the test to make runs for specific tests easier, e.g. swift package benchmark --filter predicateKeypathPropertyCondition Also added a simple variadic test to see what the impact would be when going from 1 -> 2 at least (seems to be 30% or so). Definitely room for extending that later. |
…till get enough samples and stable results
@swift-ci please test |
1 similar comment
@swift-ci please test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great now, thanks for all the work on this! I'm excited to build upon this with more benchmarks in the future.
Sounds great, thanks - if you are interested in adding the benchmark suite into CI for regression checking in the future, I would suggest having a look at how swift-nio does it. Happy to help out if you run into any questions on the usage of package-benchmark if looking at wider adoption (and we'll provide new PR:s for any performance issues we run into, currently we are focused on adopting Predicates though). |
Good to know, thanks! @iCharlesHu and I were discussing this earlier, so Charles it looks like that'd be a good place to start.
Sounds great! Definitely let us know if you hit other performance bottlenecks and we can definitely take a look to see if we can come up with some solutions! |
Motivation
Predicate matching performance is 10x slower over custom implementation, this PR adds benchmark plugin to get a baseline performance and to help future Predicates development.
Benchmark is added in the same fashion as for swift-nio and swift-certifcates.
There are 5 benchmarks.
The most common case for our product is more than one condition, and we widely use computed properties, so if we will use more than 3 conditions then we will have throughout less than 600K/sec, which not too much for us.
All benchmarks can be executed with
swift package benchmark --scale
in the project 'Benchmarks' directory.We observe


swift_getAtKeyPath
execution takes significant time relative to whole execution time.The issue can be reproduced with a nested computed properties in benchmark (4) and (5). A single benchmark can be executed with command
swift package benchmark --scale --filter "Predicate #5 - 3 KeyPath nested computed property conditions"
Also we observe that predicate evaluation entails few malloc calls, what is also possibly the cause of poor performance.
Each benchmark report a set of information, the most interesting for now is a 'Throughput' line, which shows how many evaluations per second can be executed.
To run with profile in Xcode:
Running benchmarks in Xcode and using Instruments for profiling benchmarks
Profiling benchmarks or building the benchmarks in release mode in Xcode with jemalloc is currently not supported (as Xcode currently doesn’t support interposition of the malloc library) and requires disabling jemalloc.
Make sure Xcode is closed and then open it from the CLI with the BENCHMARK_DISABLE_JEMALLOC environment variable set e.g.:
This will disable the jemalloc dependency and you can simply build in Xcode for profiling and use Instruments as normal - including signpost information for the benchmark run.