package-benchmark icon indicating copy to clipboard operation
package-benchmark copied to clipboard

Swift 6 language mode support needed

Open hassila opened this issue 1 year ago • 1 comments

let 'benchmarks' is not concurrency-safe because non-'Sendable' type '() -> ()' may have shared mutable state

hassila avatar Jun 14 '24 07:06 hassila

~What is the workaround here?~

Use explicit type:

let benchmarks : @Sendable () -> Benchmark? = {

t089 avatar Sep 28 '24 21:09 t089

If you have many Benchmark:

let benchmarks : @Sendable () -> Void = {

toffaletti avatar Oct 14 '24 12:10 toffaletti

Would also be nice to conform BenchmarkMetric to Sendable since we currently can't define custom metrics like so:

enum CustomMeasurement {
    static let forward = BenchmarkMetric.custom("run forward (ns)", polarity: .prefersSmaller, useScalingFactor: true)
    static let reverse = BenchmarkMetric.custom("run reverse (ns)", polarity: .prefersSmaller, useScalingFactor: true)
    static let ratio = BenchmarkMetric.custom("ratio", polarity: .prefersSmaller, useScalingFactor: true)
}

returns the following error: Static property 'forward' is not concurrency-safe because non-'Sendable' type 'BenchmarkMetric' may have shared mutable state

There's also an issue when setting the defaultConfiguration for benchmarks like so:

let benchmarks: @Sendable () -> Void = {
    Benchmark.defaultConfiguration = .init( // Reference to class property 'defaultConfiguration' is not concurrency-safe because it involves shared mutable state
        warmupIterations: 1,
        scalingFactor: .kilo
    )
    
    Benchmark("b1") {
        // ...
    }
}

Are there workarounds for these? I think we can make BenchmarkMetric conform to Sendable right? But for the Benchmark.defaultConfiguration I'm not sure what a good solution would be.

JaapWijnen avatar Dec 19 '24 13:12 JaapWijnen

Making BenchmarkMetric conform to Sendable in https://github.com/ordo-one/package-benchmark/pull/309

The defaultConfiguration I need to have a look at.

hassila avatar Feb 11 '25 12:02 hassila

I fixed defaultConfiguration too with a lock, I think Swift 6 benchmarks targets should be completely possible now with https://github.com/ordo-one/package-benchmark/releases/tag/1.28.0

Please give it a spin and open new issues if you find anything remaining.

hassila avatar Feb 11 '25 12:02 hassila

Nice will give it a try thanks!

JaapWijnen avatar Feb 12 '25 10:02 JaapWijnen