Skip to content

Commit bf4a4c3

Browse files
inline histogram record (gives 10x boost) (#124)
Before inlining: ``` ==================== PrometheusBenchmarks ==================== DurationHistogram ╒═══════════════════════════════╤═══════════╤═══════════╤═══════════╤═══════════╤═══════════╤═══════════╤═══════════╤═══════════╕ │ Metric │ p0 │ p25 │ p50 │ p75 │ p90 │ p99 │ p100 │ Samples │ ╞═══════════════════════════════╪═══════════╪═══════════╪═══════════╪═══════════╪═══════════╪═══════════╪═══════════╪═══════════╡ │ Instructions * │ 3213 │ 3215 │ 3215 │ 3217 │ 3219 │ 3432 │ 3452 │ 10000 │ ├───────────────────────────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤ │ Malloc (total) * │ 0 │ 0 │ 0 │ 0 │ 0 │ 0 │ 0 │ 10000 │ ├───────────────────────────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤ │ Memory (resident peak) (K) │ 8421 │ 8757 │ 8774 │ 8790 │ 8798 │ 8798 │ 8798 │ 10000 │ ├───────────────────────────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤ │ Throughput (# / s) (K) │ 4556 │ 4135 │ 4009 │ 3877 │ 3765 │ 3569 │ 3272 │ 10000 │ ├───────────────────────────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤ │ Time (total CPU) (ns) * │ 221 │ 244 │ 252 │ 260 │ 268 │ 282 │ 307 │ 10000 │ ├───────────────────────────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤ │ Time (wall clock) (ns) * │ 220 │ 242 │ 249 │ 258 │ 266 │ 280 │ 306 │ 10000 │ ╘═══════════════════════════════╧═══════════╧═══════════╧═══════════╧═══════════╧═══════════╧═══════════╧═══════════╧═══════════╛ ``` After inlining: ``` ==================== PrometheusBenchmarks ==================== DurationHistogram ╒═══════════════════════════════╤═══════════╤═══════════╤═══════════╤═══════════╤═══════════╤═══════════╤═══════════╤═══════════╕ │ Metric │ p0 │ p25 │ p50 │ p75 │ p90 │ p99 │ p100 │ Samples │ ╞═══════════════════════════════╪═══════════╪═══════════╪═══════════╪═══════════╪═══════════╪═══════════╪═══════════╪═══════════╡ │ Instructions * │ 281 │ 281 │ 281 │ 281 │ 281 │ 283 │ 299 │ 10000 │ ├───────────────────────────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤ │ Malloc (total) * │ 0 │ 0 │ 0 │ 0 │ 0 │ 0 │ 0 │ 10000 │ ├───────────────────────────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤ │ Memory (resident peak) (K) │ 8405 │ 8724 │ 8741 │ 8757 │ 8765 │ 8765 │ 8765 │ 10000 │ ├───────────────────────────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤ │ Throughput (# / s) (M) │ 53 │ 51 │ 51 │ 48 │ 42 │ 36 │ 26 │ 10000 │ ├───────────────────────────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤ │ Time (total CPU) (ns) * │ 20 │ 21 │ 22 │ 23 │ 26 │ 30 │ 40 │ 10000 │ ├───────────────────────────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤ │ Time (wall clock) (ns) * │ 19 │ 20 │ 20 │ 21 │ 24 │ 28 │ 39 │ 10000 │ ╘═══════════════════════════════╧═══════════╧═══════════╧═══════════╧═══════════╧═══════════╧═══════════╧═══════════╧═══════════╛ ``` Used cherry pick benchmarks from this PR: #106
1 parent ba92571 commit bf4a4c3

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

Sources/Prometheus/Histogram.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public final class Histogram<Value: Bucketable>: Sendable {
5656
self.box = .init(.init(buckets: buckets))
5757
}
5858

59+
@inlinable
5960
public func record(_ value: Value) {
6061
self.box.withLockedValue { state in
6162
for i in state.buckets.startIndex..<state.buckets.endIndex {

0 commit comments

Comments
 (0)