Skip to content

Commit 634f7ec

Browse files
committed
perf: Improve @foxify/fresh stale check performance
1 parent 39e5736 commit 634f7ec

3 files changed

Lines changed: 17 additions & 14 deletions

File tree

‎.changeset/long-hairs-train.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@foxify/fresh": patch
3+
---
4+
5+
Improve stale check performance

‎benchmarks/fresh/README.md‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,30 @@
66
ℹ Benchmark: etag-several
77
2 tests completed.
88

9-
@foxify/fresh x 47,660,237 ops/sec ±0.18% (99 runs sampled)
10-
fresh x 6,465,652 ops/sec ±0.80% (96 runs sampled)
9+
@foxify/fresh x 46,643,956 ops/sec ±0.08% (99 runs sampled)
10+
fresh x 6,464,804 ops/sec ±0.15% (99 runs sampled)
1111

1212
ℹ Benchmark: etag-single
1313
2 tests completed.
1414

15-
@foxify/fresh x 60,990,697 ops/sec ±0.50% (100 runs sampled)
16-
fresh x 28,459,834 ops/sec ±0.33% (99 runs sampled)
15+
@foxify/fresh x 59,921,046 ops/sec ±0.22% (97 runs sampled)
16+
fresh x 26,579,845 ops/sec ±1.25% (95 runs sampled)
1717

1818
ℹ Benchmark: etag-star
1919
2 tests completed.
2020

21-
@foxify/fresh x 154,660,013 ops/sec ±0.11% (99 runs sampled)
22-
fresh x 155,164,859 ops/sec ±0.11% (99 runs sampled)
21+
@foxify/fresh x 149,770,865 ops/sec ±0.24% (100 runs sampled)
22+
fresh x 149,440,474 ops/sec ±0.30% (98 runs sampled)
2323

2424
ℹ Benchmark: modified
2525
2 tests completed.
2626

27-
@foxify/fresh x 3,178,965 ops/sec ±0.19% (98 runs sampled)
28-
fresh x 3,103,903 ops/sec ±0.19% (99 runs sampled)
27+
@foxify/fresh x 3,101,171 ops/sec ±0.08% (97 runs sampled)
28+
fresh x 3,029,379 ops/sec ±0.14% (99 runs sampled)
2929

3030
ℹ Benchmark: not-modified
3131
2 tests completed.
3232

33-
@foxify/fresh x 3,187,981 ops/sec ±0.24% (98 runs sampled)
34-
fresh x 3,150,836 ops/sec ±0.22% (94 runs sampled)
33+
@foxify/fresh x 3,125,705 ops/sec ±0.10% (100 runs sampled)
34+
fresh x 3,058,272 ops/sec ±0.09% (99 runs sampled)
3535
```

‎packages/fresh/src/index.ts‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { IncomingHttpHeaders, OutgoingHttpHeaders } from "http";
1+
import { IncomingHttpHeaders, OutgoingHttpHeaders } from "node:http";
22

33
/**
44
* RegExp to check for no-cache token in Cache-Control.
@@ -46,9 +46,7 @@ function isStale(etag: string, noneMatch: string): boolean {
4646
}
4747
}
4848

49-
if (compareETags(etag, noneMatch.substring(start, end))) return false;
50-
51-
return true;
49+
return !compareETags(etag, noneMatch.substring(start, end));
5250
}
5351

5452
/**

0 commit comments

Comments
 (0)