mirror of
https://github.com/apple/swift-collections
synced 2026-11-29 05:14:20 +00:00
When ingesting a `String` instance, `BigString` assumes that the input string has a reasonably efficient UTF-8 view. Unfortunately, that is very much not the case when the input happens to be backed by a bridged NSString object — it appears that in this case, the ingester loop invokes some operation(s) with linear complexity in the size of the entire input, rendering the ingester’s overall complexity quadratic. The BigString ingester is only expected to operate within a single chunk at the time. It’s unclear precisely which operation triggers the quadratic behavior; ideally we should figure it out and resolve it with a more targeted fix. In the meantime, a blunt stopgap fix is to force-transcode the input string to UTF-8 at the time the ingester is initialized. This unnecessarily wastes some (temporary) memory on holding the transcoded string, but it avoids the quadratic cliff.
46 lines
1.4 KiB
Swift
46 lines
1.4 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the Swift Collections open source project
|
|
//
|
|
// Copyright (c) 2021 - 2024 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See https://swift.org/LICENSE.txt for license information
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
import CollectionsBenchmark
|
|
import Benchmarks
|
|
import DequeModule
|
|
|
|
if Deque<Int>._isConsistencyCheckingEnabled {
|
|
complain("""
|
|
*** INTERNAL CONSISTENCY CHECKING IS ENABLED ***
|
|
|
|
Performance guarantees aren't valid in this configuration,
|
|
and benchmarking data will be largely useless. Proceed at
|
|
your own risk.
|
|
|
|
""")
|
|
}
|
|
|
|
var benchmark = Benchmark(title: "Collection Benchmarks")
|
|
benchmark.registerCustomGenerators()
|
|
benchmark.addArrayBenchmarks()
|
|
benchmark.addSetBenchmarks()
|
|
benchmark.addDictionaryBenchmarks()
|
|
benchmark.addTreeDictionaryBenchmarks()
|
|
benchmark.addDequeBenchmarks()
|
|
benchmark.addOrderedSetBenchmarks()
|
|
benchmark.addOrderedDictionaryBenchmarks()
|
|
benchmark.addHeapBenchmarks()
|
|
benchmark.addBitSetBenchmarks()
|
|
benchmark.addTreeSetBenchmarks()
|
|
benchmark.addCppBenchmarks()
|
|
benchmark.addBigStringBenchmarks()
|
|
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
|
|
benchmark.addFoundationBenchmarks()
|
|
#endif
|
|
|
|
benchmark.main()
|