From 6c8ca8297332ea2780c45e1bce9d7fd2a8b51e1d Mon Sep 17 00:00:00 2001 From: Mathias Quintero Date: Thu, 3 Sep 2026 16:00:23 +0100 Subject: [PATCH] Improve allocations in Large Field Equality Checks (#150) ### Motivation Checking for equality of multiple http fields creates an array per field name. However, not every field will actually have multiple values, which means we can save array allocations for fields that are only set once. ### Modifications - Added an enum to handle single values without extra allocations ### Result Faster equality checks. --- ...al-allDistinctNamesReversed-N=128.p90.json | 2 +- ...al-allDistinctNamesReversed-N=256.p90.json | 2 +- ...al-allDistinctNamesReversed-N=512.p90.json | 2 +- ...al-allDistinctNamesReversed-N=128.p90.json | 2 +- ...ual-allDistinctNamesReversed-N=16.p90.json | 2 +- ...al-allDistinctNamesReversed-N=256.p90.json | 2 +- ...ual-allDistinctNamesReversed-N=32.p90.json | 2 +- ...al-allDistinctNamesReversed-N=512.p90.json | 2 +- ...ual-allDistinctNamesReversed-N=64.p90.json | 2 +- ...qual-allDistinctNamesReversed-N=8.p90.json | 2 +- ...al-allDistinctNamesReversed-N=128.p90.json | 2 +- ...al-allDistinctNamesReversed-N=256.p90.json | 2 +- ...al-allDistinctNamesReversed-N=512.p90.json | 2 +- ...al-allDistinctNamesReversed-N=128.p90.json | 2 +- ...ual-allDistinctNamesReversed-N=16.p90.json | 2 +- ...al-allDistinctNamesReversed-N=256.p90.json | 2 +- ...ual-allDistinctNamesReversed-N=32.p90.json | 2 +- ...al-allDistinctNamesReversed-N=512.p90.json | 2 +- ...ual-allDistinctNamesReversed-N=64.p90.json | 2 +- ...qual-allDistinctNamesReversed-N=8.p90.json | 2 +- ...al-allDistinctNamesReversed-N=128.p90.json | 2 +- ...al-allDistinctNamesReversed-N=256.p90.json | 2 +- ...al-allDistinctNamesReversed-N=512.p90.json | 2 +- ...al-allDistinctNamesReversed-N=128.p90.json | 2 +- ...ual-allDistinctNamesReversed-N=16.p90.json | 2 +- ...al-allDistinctNamesReversed-N=256.p90.json | 2 +- ...ual-allDistinctNamesReversed-N=32.p90.json | 2 +- ...al-allDistinctNamesReversed-N=512.p90.json | 2 +- ...ual-allDistinctNamesReversed-N=64.p90.json | 2 +- ...qual-allDistinctNamesReversed-N=8.p90.json | 2 +- ...al-allDistinctNamesReversed-N=128.p90.json | 2 +- ...al-allDistinctNamesReversed-N=256.p90.json | 2 +- ...al-allDistinctNamesReversed-N=512.p90.json | 2 +- ...al-allDistinctNamesReversed-N=128.p90.json | 2 +- ...ual-allDistinctNamesReversed-N=16.p90.json | 2 +- ...al-allDistinctNamesReversed-N=256.p90.json | 2 +- ...ual-allDistinctNamesReversed-N=32.p90.json | 2 +- ...al-allDistinctNamesReversed-N=512.p90.json | 2 +- ...ual-allDistinctNamesReversed-N=64.p90.json | 2 +- ...qual-allDistinctNamesReversed-N=8.p90.json | 2 +- ...al-allDistinctNamesReversed-N=128.p90.json | 2 +- ...al-allDistinctNamesReversed-N=256.p90.json | 2 +- ...al-allDistinctNamesReversed-N=512.p90.json | 2 +- ...al-allDistinctNamesReversed-N=128.p90.json | 2 +- ...ual-allDistinctNamesReversed-N=16.p90.json | 2 +- ...al-allDistinctNamesReversed-N=256.p90.json | 2 +- ...ual-allDistinctNamesReversed-N=32.p90.json | 2 +- ...al-allDistinctNamesReversed-N=512.p90.json | 2 +- ...ual-allDistinctNamesReversed-N=64.p90.json | 2 +- ...qual-allDistinctNamesReversed-N=8.p90.json | 2 +- Sources/HTTPTypes/HTTPFields.swift | 47 +++++++++++++++++-- 51 files changed, 93 insertions(+), 54 deletions(-) diff --git a/Benchmarks/Thresholds/6.1/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=128.p90.json b/Benchmarks/Thresholds/6.1/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=128.p90.json index 63ed127..1726cdd 100644 --- a/Benchmarks/Thresholds/6.1/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=128.p90.json +++ b/Benchmarks/Thresholds/6.1/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=128.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 147 + "mallocCountTotal" : 19 } \ No newline at end of file diff --git a/Benchmarks/Thresholds/6.1/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=256.p90.json b/Benchmarks/Thresholds/6.1/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=256.p90.json index c8d5311..1726cdd 100644 --- a/Benchmarks/Thresholds/6.1/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=256.p90.json +++ b/Benchmarks/Thresholds/6.1/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=256.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 275 + "mallocCountTotal" : 19 } \ No newline at end of file diff --git a/Benchmarks/Thresholds/6.1/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=512.p90.json b/Benchmarks/Thresholds/6.1/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=512.p90.json index a11d416..1726cdd 100644 --- a/Benchmarks/Thresholds/6.1/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=512.p90.json +++ b/Benchmarks/Thresholds/6.1/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=512.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 531 + "mallocCountTotal" : 19 } \ No newline at end of file diff --git a/Benchmarks/Thresholds/6.1/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=128.p90.json b/Benchmarks/Thresholds/6.1/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=128.p90.json index dc4d0a8..106b3a6 100644 --- a/Benchmarks/Thresholds/6.1/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=128.p90.json +++ b/Benchmarks/Thresholds/6.1/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=128.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 145 + "mallocCountTotal" : 17 } \ No newline at end of file diff --git a/Benchmarks/Thresholds/6.1/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=16.p90.json b/Benchmarks/Thresholds/6.1/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=16.p90.json index 14b7967..106b3a6 100644 --- a/Benchmarks/Thresholds/6.1/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=16.p90.json +++ b/Benchmarks/Thresholds/6.1/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=16.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 33 + "mallocCountTotal" : 17 } \ No newline at end of file diff --git a/Benchmarks/Thresholds/6.1/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=256.p90.json b/Benchmarks/Thresholds/6.1/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=256.p90.json index 07858cd..106b3a6 100644 --- a/Benchmarks/Thresholds/6.1/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=256.p90.json +++ b/Benchmarks/Thresholds/6.1/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=256.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 273 + "mallocCountTotal" : 17 } \ No newline at end of file diff --git a/Benchmarks/Thresholds/6.1/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=32.p90.json b/Benchmarks/Thresholds/6.1/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=32.p90.json index 7656136..106b3a6 100644 --- a/Benchmarks/Thresholds/6.1/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=32.p90.json +++ b/Benchmarks/Thresholds/6.1/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=32.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 49 + "mallocCountTotal" : 17 } \ No newline at end of file diff --git a/Benchmarks/Thresholds/6.1/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=512.p90.json b/Benchmarks/Thresholds/6.1/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=512.p90.json index 6898c33..106b3a6 100644 --- a/Benchmarks/Thresholds/6.1/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=512.p90.json +++ b/Benchmarks/Thresholds/6.1/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=512.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 529 + "mallocCountTotal" : 17 } \ No newline at end of file diff --git a/Benchmarks/Thresholds/6.1/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=64.p90.json b/Benchmarks/Thresholds/6.1/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=64.p90.json index ec9e0c6..106b3a6 100644 --- a/Benchmarks/Thresholds/6.1/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=64.p90.json +++ b/Benchmarks/Thresholds/6.1/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=64.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 81 + "mallocCountTotal" : 17 } \ No newline at end of file diff --git a/Benchmarks/Thresholds/6.1/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=8.p90.json b/Benchmarks/Thresholds/6.1/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=8.p90.json index fcde1ab..106b3a6 100644 --- a/Benchmarks/Thresholds/6.1/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=8.p90.json +++ b/Benchmarks/Thresholds/6.1/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=8.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 25 + "mallocCountTotal" : 17 } \ No newline at end of file diff --git a/Benchmarks/Thresholds/6.2/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=128.p90.json b/Benchmarks/Thresholds/6.2/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=128.p90.json index 63ed127..1726cdd 100644 --- a/Benchmarks/Thresholds/6.2/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=128.p90.json +++ b/Benchmarks/Thresholds/6.2/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=128.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 147 + "mallocCountTotal" : 19 } \ No newline at end of file diff --git a/Benchmarks/Thresholds/6.2/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=256.p90.json b/Benchmarks/Thresholds/6.2/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=256.p90.json index c8d5311..1726cdd 100644 --- a/Benchmarks/Thresholds/6.2/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=256.p90.json +++ b/Benchmarks/Thresholds/6.2/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=256.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 275 + "mallocCountTotal" : 19 } \ No newline at end of file diff --git a/Benchmarks/Thresholds/6.2/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=512.p90.json b/Benchmarks/Thresholds/6.2/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=512.p90.json index a11d416..1726cdd 100644 --- a/Benchmarks/Thresholds/6.2/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=512.p90.json +++ b/Benchmarks/Thresholds/6.2/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=512.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 531 + "mallocCountTotal" : 19 } \ No newline at end of file diff --git a/Benchmarks/Thresholds/6.2/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=128.p90.json b/Benchmarks/Thresholds/6.2/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=128.p90.json index dc4d0a8..106b3a6 100644 --- a/Benchmarks/Thresholds/6.2/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=128.p90.json +++ b/Benchmarks/Thresholds/6.2/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=128.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 145 + "mallocCountTotal" : 17 } \ No newline at end of file diff --git a/Benchmarks/Thresholds/6.2/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=16.p90.json b/Benchmarks/Thresholds/6.2/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=16.p90.json index 14b7967..106b3a6 100644 --- a/Benchmarks/Thresholds/6.2/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=16.p90.json +++ b/Benchmarks/Thresholds/6.2/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=16.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 33 + "mallocCountTotal" : 17 } \ No newline at end of file diff --git a/Benchmarks/Thresholds/6.2/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=256.p90.json b/Benchmarks/Thresholds/6.2/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=256.p90.json index 07858cd..106b3a6 100644 --- a/Benchmarks/Thresholds/6.2/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=256.p90.json +++ b/Benchmarks/Thresholds/6.2/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=256.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 273 + "mallocCountTotal" : 17 } \ No newline at end of file diff --git a/Benchmarks/Thresholds/6.2/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=32.p90.json b/Benchmarks/Thresholds/6.2/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=32.p90.json index 7656136..106b3a6 100644 --- a/Benchmarks/Thresholds/6.2/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=32.p90.json +++ b/Benchmarks/Thresholds/6.2/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=32.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 49 + "mallocCountTotal" : 17 } \ No newline at end of file diff --git a/Benchmarks/Thresholds/6.2/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=512.p90.json b/Benchmarks/Thresholds/6.2/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=512.p90.json index 6898c33..106b3a6 100644 --- a/Benchmarks/Thresholds/6.2/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=512.p90.json +++ b/Benchmarks/Thresholds/6.2/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=512.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 529 + "mallocCountTotal" : 17 } \ No newline at end of file diff --git a/Benchmarks/Thresholds/6.2/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=64.p90.json b/Benchmarks/Thresholds/6.2/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=64.p90.json index ec9e0c6..106b3a6 100644 --- a/Benchmarks/Thresholds/6.2/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=64.p90.json +++ b/Benchmarks/Thresholds/6.2/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=64.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 81 + "mallocCountTotal" : 17 } \ No newline at end of file diff --git a/Benchmarks/Thresholds/6.2/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=8.p90.json b/Benchmarks/Thresholds/6.2/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=8.p90.json index fcde1ab..106b3a6 100644 --- a/Benchmarks/Thresholds/6.2/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=8.p90.json +++ b/Benchmarks/Thresholds/6.2/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=8.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 25 + "mallocCountTotal" : 17 } \ No newline at end of file diff --git a/Benchmarks/Thresholds/6.3/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=128.p90.json b/Benchmarks/Thresholds/6.3/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=128.p90.json index 97fb7d7..c3df4ca 100644 --- a/Benchmarks/Thresholds/6.3/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=128.p90.json +++ b/Benchmarks/Thresholds/6.3/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=128.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 149 + "mallocCountTotal" : 21 } \ No newline at end of file diff --git a/Benchmarks/Thresholds/6.3/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=256.p90.json b/Benchmarks/Thresholds/6.3/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=256.p90.json index 72f695e..c3df4ca 100644 --- a/Benchmarks/Thresholds/6.3/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=256.p90.json +++ b/Benchmarks/Thresholds/6.3/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=256.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 277 + "mallocCountTotal" : 21 } \ No newline at end of file diff --git a/Benchmarks/Thresholds/6.3/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=512.p90.json b/Benchmarks/Thresholds/6.3/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=512.p90.json index 83da394..c3df4ca 100644 --- a/Benchmarks/Thresholds/6.3/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=512.p90.json +++ b/Benchmarks/Thresholds/6.3/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=512.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 533 + "mallocCountTotal" : 21 } \ No newline at end of file diff --git a/Benchmarks/Thresholds/6.3/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=128.p90.json b/Benchmarks/Thresholds/6.3/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=128.p90.json index 63ed127..1726cdd 100644 --- a/Benchmarks/Thresholds/6.3/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=128.p90.json +++ b/Benchmarks/Thresholds/6.3/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=128.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 147 + "mallocCountTotal" : 19 } \ No newline at end of file diff --git a/Benchmarks/Thresholds/6.3/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=16.p90.json b/Benchmarks/Thresholds/6.3/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=16.p90.json index 9cc9b28..1726cdd 100644 --- a/Benchmarks/Thresholds/6.3/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=16.p90.json +++ b/Benchmarks/Thresholds/6.3/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=16.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 35 + "mallocCountTotal" : 19 } \ No newline at end of file diff --git a/Benchmarks/Thresholds/6.3/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=256.p90.json b/Benchmarks/Thresholds/6.3/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=256.p90.json index c8d5311..1726cdd 100644 --- a/Benchmarks/Thresholds/6.3/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=256.p90.json +++ b/Benchmarks/Thresholds/6.3/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=256.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 275 + "mallocCountTotal" : 19 } \ No newline at end of file diff --git a/Benchmarks/Thresholds/6.3/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=32.p90.json b/Benchmarks/Thresholds/6.3/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=32.p90.json index 50cfb4c..1726cdd 100644 --- a/Benchmarks/Thresholds/6.3/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=32.p90.json +++ b/Benchmarks/Thresholds/6.3/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=32.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 51 + "mallocCountTotal" : 19 } \ No newline at end of file diff --git a/Benchmarks/Thresholds/6.3/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=512.p90.json b/Benchmarks/Thresholds/6.3/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=512.p90.json index a11d416..1726cdd 100644 --- a/Benchmarks/Thresholds/6.3/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=512.p90.json +++ b/Benchmarks/Thresholds/6.3/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=512.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 531 + "mallocCountTotal" : 19 } \ No newline at end of file diff --git a/Benchmarks/Thresholds/6.3/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=64.p90.json b/Benchmarks/Thresholds/6.3/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=64.p90.json index fc142ef..1726cdd 100644 --- a/Benchmarks/Thresholds/6.3/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=64.p90.json +++ b/Benchmarks/Thresholds/6.3/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=64.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 83 + "mallocCountTotal" : 19 } \ No newline at end of file diff --git a/Benchmarks/Thresholds/6.3/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=8.p90.json b/Benchmarks/Thresholds/6.3/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=8.p90.json index 76605fa..1726cdd 100644 --- a/Benchmarks/Thresholds/6.3/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=8.p90.json +++ b/Benchmarks/Thresholds/6.3/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=8.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 27 + "mallocCountTotal" : 19 } \ No newline at end of file diff --git a/Benchmarks/Thresholds/nightly-main/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=128.p90.json b/Benchmarks/Thresholds/nightly-main/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=128.p90.json index 97fb7d7..c3df4ca 100644 --- a/Benchmarks/Thresholds/nightly-main/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=128.p90.json +++ b/Benchmarks/Thresholds/nightly-main/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=128.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 149 + "mallocCountTotal" : 21 } \ No newline at end of file diff --git a/Benchmarks/Thresholds/nightly-main/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=256.p90.json b/Benchmarks/Thresholds/nightly-main/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=256.p90.json index 72f695e..c3df4ca 100644 --- a/Benchmarks/Thresholds/nightly-main/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=256.p90.json +++ b/Benchmarks/Thresholds/nightly-main/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=256.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 277 + "mallocCountTotal" : 21 } \ No newline at end of file diff --git a/Benchmarks/Thresholds/nightly-main/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=512.p90.json b/Benchmarks/Thresholds/nightly-main/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=512.p90.json index 83da394..c3df4ca 100644 --- a/Benchmarks/Thresholds/nightly-main/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=512.p90.json +++ b/Benchmarks/Thresholds/nightly-main/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=512.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 533 + "mallocCountTotal" : 21 } \ No newline at end of file diff --git a/Benchmarks/Thresholds/nightly-main/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=128.p90.json b/Benchmarks/Thresholds/nightly-main/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=128.p90.json index 63ed127..1726cdd 100644 --- a/Benchmarks/Thresholds/nightly-main/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=128.p90.json +++ b/Benchmarks/Thresholds/nightly-main/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=128.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 147 + "mallocCountTotal" : 19 } \ No newline at end of file diff --git a/Benchmarks/Thresholds/nightly-main/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=16.p90.json b/Benchmarks/Thresholds/nightly-main/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=16.p90.json index 9cc9b28..1726cdd 100644 --- a/Benchmarks/Thresholds/nightly-main/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=16.p90.json +++ b/Benchmarks/Thresholds/nightly-main/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=16.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 35 + "mallocCountTotal" : 19 } \ No newline at end of file diff --git a/Benchmarks/Thresholds/nightly-main/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=256.p90.json b/Benchmarks/Thresholds/nightly-main/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=256.p90.json index c8d5311..1726cdd 100644 --- a/Benchmarks/Thresholds/nightly-main/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=256.p90.json +++ b/Benchmarks/Thresholds/nightly-main/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=256.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 275 + "mallocCountTotal" : 19 } \ No newline at end of file diff --git a/Benchmarks/Thresholds/nightly-main/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=32.p90.json b/Benchmarks/Thresholds/nightly-main/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=32.p90.json index 50cfb4c..1726cdd 100644 --- a/Benchmarks/Thresholds/nightly-main/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=32.p90.json +++ b/Benchmarks/Thresholds/nightly-main/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=32.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 51 + "mallocCountTotal" : 19 } \ No newline at end of file diff --git a/Benchmarks/Thresholds/nightly-main/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=512.p90.json b/Benchmarks/Thresholds/nightly-main/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=512.p90.json index a11d416..1726cdd 100644 --- a/Benchmarks/Thresholds/nightly-main/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=512.p90.json +++ b/Benchmarks/Thresholds/nightly-main/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=512.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 531 + "mallocCountTotal" : 19 } \ No newline at end of file diff --git a/Benchmarks/Thresholds/nightly-main/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=64.p90.json b/Benchmarks/Thresholds/nightly-main/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=64.p90.json index fc142ef..1726cdd 100644 --- a/Benchmarks/Thresholds/nightly-main/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=64.p90.json +++ b/Benchmarks/Thresholds/nightly-main/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=64.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 83 + "mallocCountTotal" : 19 } \ No newline at end of file diff --git a/Benchmarks/Thresholds/nightly-main/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=8.p90.json b/Benchmarks/Thresholds/nightly-main/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=8.p90.json index 76605fa..1726cdd 100644 --- a/Benchmarks/Thresholds/nightly-main/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=8.p90.json +++ b/Benchmarks/Thresholds/nightly-main/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=8.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 27 + "mallocCountTotal" : 19 } \ No newline at end of file diff --git a/Benchmarks/Thresholds/nightly-next/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=128.p90.json b/Benchmarks/Thresholds/nightly-next/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=128.p90.json index 97fb7d7..c3df4ca 100644 --- a/Benchmarks/Thresholds/nightly-next/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=128.p90.json +++ b/Benchmarks/Thresholds/nightly-next/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=128.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 149 + "mallocCountTotal" : 21 } \ No newline at end of file diff --git a/Benchmarks/Thresholds/nightly-next/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=256.p90.json b/Benchmarks/Thresholds/nightly-next/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=256.p90.json index 72f695e..c3df4ca 100644 --- a/Benchmarks/Thresholds/nightly-next/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=256.p90.json +++ b/Benchmarks/Thresholds/nightly-next/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=256.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 277 + "mallocCountTotal" : 21 } \ No newline at end of file diff --git a/Benchmarks/Thresholds/nightly-next/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=512.p90.json b/Benchmarks/Thresholds/nightly-next/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=512.p90.json index 83da394..c3df4ca 100644 --- a/Benchmarks/Thresholds/nightly-next/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=512.p90.json +++ b/Benchmarks/Thresholds/nightly-next/Benchmarks.HTTPFields.==-equal-allDistinctNamesReversed-N=512.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 533 + "mallocCountTotal" : 21 } \ No newline at end of file diff --git a/Benchmarks/Thresholds/nightly-next/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=128.p90.json b/Benchmarks/Thresholds/nightly-next/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=128.p90.json index 63ed127..1726cdd 100644 --- a/Benchmarks/Thresholds/nightly-next/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=128.p90.json +++ b/Benchmarks/Thresholds/nightly-next/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=128.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 147 + "mallocCountTotal" : 19 } \ No newline at end of file diff --git a/Benchmarks/Thresholds/nightly-next/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=16.p90.json b/Benchmarks/Thresholds/nightly-next/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=16.p90.json index 9cc9b28..1726cdd 100644 --- a/Benchmarks/Thresholds/nightly-next/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=16.p90.json +++ b/Benchmarks/Thresholds/nightly-next/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=16.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 35 + "mallocCountTotal" : 19 } \ No newline at end of file diff --git a/Benchmarks/Thresholds/nightly-next/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=256.p90.json b/Benchmarks/Thresholds/nightly-next/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=256.p90.json index c8d5311..1726cdd 100644 --- a/Benchmarks/Thresholds/nightly-next/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=256.p90.json +++ b/Benchmarks/Thresholds/nightly-next/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=256.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 275 + "mallocCountTotal" : 19 } \ No newline at end of file diff --git a/Benchmarks/Thresholds/nightly-next/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=32.p90.json b/Benchmarks/Thresholds/nightly-next/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=32.p90.json index 50cfb4c..1726cdd 100644 --- a/Benchmarks/Thresholds/nightly-next/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=32.p90.json +++ b/Benchmarks/Thresholds/nightly-next/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=32.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 51 + "mallocCountTotal" : 19 } \ No newline at end of file diff --git a/Benchmarks/Thresholds/nightly-next/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=512.p90.json b/Benchmarks/Thresholds/nightly-next/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=512.p90.json index a11d416..1726cdd 100644 --- a/Benchmarks/Thresholds/nightly-next/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=512.p90.json +++ b/Benchmarks/Thresholds/nightly-next/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=512.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 531 + "mallocCountTotal" : 19 } \ No newline at end of file diff --git a/Benchmarks/Thresholds/nightly-next/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=64.p90.json b/Benchmarks/Thresholds/nightly-next/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=64.p90.json index fc142ef..1726cdd 100644 --- a/Benchmarks/Thresholds/nightly-next/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=64.p90.json +++ b/Benchmarks/Thresholds/nightly-next/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=64.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 83 + "mallocCountTotal" : 19 } \ No newline at end of file diff --git a/Benchmarks/Thresholds/nightly-next/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=8.p90.json b/Benchmarks/Thresholds/nightly-next/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=8.p90.json index 76605fa..1726cdd 100644 --- a/Benchmarks/Thresholds/nightly-next/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=8.p90.json +++ b/Benchmarks/Thresholds/nightly-next/Benchmarks.HTTPFields.isEqualByNameIndex-equal-allDistinctNamesReversed-N=8.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 27 + "mallocCountTotal" : 19 } \ No newline at end of file diff --git a/Sources/HTTPTypes/HTTPFields.swift b/Sources/HTTPTypes/HTTPFields.swift index 3cc5a3d..8bb19a1 100644 --- a/Sources/HTTPTypes/HTTPFields.swift +++ b/Sources/HTTPTypes/HTTPFields.swift @@ -286,6 +286,46 @@ extension HTTPFields: Equatable { /// compare in lock-step. private static var minFieldsToIndexByName: Int { 64 } + private enum FieldEqualityGroup { + case empty + case single(HTTPField) + case multiple([HTTPField]) + + mutating func append(_ newElement: HTTPField) { + switch self { + case .empty: + self = .single(newElement) + case .single(let element): + self = .multiple([element, newElement]) + case .multiple(var elements): + elements.append(newElement) + self = .multiple(elements) + } + } + + mutating func popLast() -> HTTPField? { + switch self { + case .empty: + return nil + case .single(let field): + self = .empty + return field + case .multiple(var fields): + let field = fields.removeLast() + guard let first = fields.first else { + self = .empty + return field + } + if fields.count < 2 { + self = .single(first) + } else { + self = .multiple(fields) + } + return field + } + } + } + /// Answers the same question as `==` in linear time, by indexing `rhs` by name and draining that /// index while walking `lhs`. @_spi(HTTPTypesBenchmarking) @@ -298,20 +338,19 @@ extension HTTPFields: Equatable { // another way to create a FIFO structure: By adding the fields to the dictionary in reverse // order, we'll add later values first to the values array. This allows us, when iterating // the lhs fields, to remove values from the end of the values array. - var remaining = [String: [HTTPField]](minimumCapacity: lhs._fields.count) + var remaining = [String: FieldEqualityGroup](minimumCapacity: lhs._fields.count) for field in rhs._fields.reversed() { - remaining[field.name.canonicalName, default: []].append(field) + remaining[field.name.canonicalName, default: .empty].append(field) } for field in lhs._fields { guard let group = remaining.index(forKey: field.name.canonicalName), - let candidate = remaining.values[group].last + let candidate = remaining.values[group].popLast() else { return false } if candidate != field { return false } - remaining.values[group].removeLast() } return true }