f58721b22f
s3api: optimize encodePath memory allocations ( #10252 )
...
* Optimize s3api encodePath to eliminate O(n^2) allocations
encodePath built its result via string concatenation in a loop, which is
O(n^2) in allocations. For non-ASCII (e.g. Chinese) runes it additionally
called make + hex.EncodeToString + strings.ToUpper per byte (~10 allocations
per character). Under high QPS with long non-ASCII object keys this produced
a very high allocation rate, frequent GC and long GC pauses, causing S3
request latency spikes.
Replace with a preallocated strings.Builder, a manual hex lookup table, and a
zero-allocation fast path. EncodePath now delegates to encodePath to remove
the duplicated implementation. Output is byte-for-byte identical, verified by
TestEncodePath and TestEncodePathEqual.
Benchmark (long Chinese path): 261 -> 1 allocs/op, 35810 -> 480 B/op, 7.5x faster.
Load test (50M calls): 212x fewer allocations, 76x fewer GC cycles.
* s3api: drop regexp from encodePath fast path
The unreserved-character scan already decides whether any byte needs
encoding, so reservedObjectNames.MatchString was a redundant second pass
that also ran the RE2 engine on every authenticated request. Rely on the
scan alone; output is unchanged. The ASCII fast path drops from ~188ns to
~11ns per call.
---------
Co-authored-by: LiuDoge <liudoge@LiuDogedeMacBook-Air.local >
Co-authored-by: Chris Lu <chris.lu@gmail.com >
2026-07-07 12:36:47 -07:00
..
2026-01-28 14:34:07 -08:00
2026-06-24 14:37:04 -07:00
2026-05-07 18:54:06 -07:00
2026-04-20 12:04:41 -07:00
2026-06-27 22:36:26 -07:00
2026-07-05 20:19:20 -07:00
2026-03-07 09:19:40 -08:00
2026-05-31 11:15:05 -07:00
2026-07-02 21:11:41 -07:00
2026-05-29 20:54:54 -07:00
2026-06-24 16:24:45 -07:00
2026-07-02 21:11:41 -07:00
2026-07-02 21:11:34 -07:00
2026-05-18 21:35:53 -07:00
2026-05-21 00:39:42 -07:00
2026-06-24 16:26:35 -07:00
2026-02-20 18:40:47 -08:00
2026-07-02 21:11:41 -07:00
2026-01-12 10:45:24 -08:00
2026-07-02 21:11:41 -07:00
2026-05-28 18:10:24 -07:00
2026-02-26 16:36:24 -08:00
2026-07-02 09:14:54 -07:00
2026-05-28 17:00:41 -07:00
2026-06-20 08:28:40 -07:00
2026-06-20 08:28:40 -07:00
2026-06-14 13:55:11 -07:00
2026-06-22 02:00:27 -07:00
2026-04-17 12:20:28 -07:00
2026-07-07 12:36:47 -07:00
2026-02-16 13:59:13 -08:00
2026-04-17 12:23:21 -07:00
2026-04-14 10:52:00 -07:00
2026-07-02 21:11:34 -07:00
2026-07-02 21:11:34 -07:00
2026-07-02 21:11:41 -07:00
2026-07-03 12:39:45 -07:00
2026-07-03 12:39:45 -07:00
2025-08-11 10:31:01 -07:00
2026-06-10 00:30:43 -07:00
2026-06-10 00:30:43 -07:00
2026-06-11 21:56:16 -07:00
2026-07-05 20:19:20 -07:00
2026-07-05 20:19:20 -07:00
2026-05-01 01:14:15 -07:00
2025-11-18 23:18:35 -08:00
2026-07-05 20:19:20 -07:00
2026-06-01 13:03:46 -07:00
2026-04-25 23:06:37 -07:00
2026-07-05 20:19:20 -07:00
2026-03-23 13:35:16 -07:00
2026-01-07 13:06:08 -08:00
2026-05-08 11:03:03 -07:00
2026-06-02 14:45:05 -07:00
2026-02-18 18:20:03 -08:00
2026-06-02 14:45:45 -07:00
2026-05-19 13:03:30 -07:00
2026-02-19 22:52:05 -08:00
2026-06-09 00:48:38 -07:00
2024-07-04 11:00:41 -07:00
2026-04-02 17:37:05 -07:00
2026-04-02 17:37:05 -07:00
2026-04-03 16:04:27 -07:00
2025-12-27 12:25:33 -08:00
2026-07-07 12:36:47 -07:00
2026-05-19 13:03:30 -07:00
2026-07-02 13:25:04 -07:00
2026-01-07 13:06:08 -08:00
2025-11-13 16:10:46 -08:00
2026-06-24 19:36:42 -07:00
2025-08-30 11:15:48 -07:00
2026-04-17 12:23:21 -07:00
2025-11-13 16:10:46 -08:00
2025-12-26 13:21:15 -08:00
2026-04-03 16:04:27 -07:00
2025-11-18 23:18:35 -08:00
2026-05-04 19:14:41 -07:00
2026-07-02 21:11:34 -07:00
2026-04-29 10:06:51 -07:00
2026-04-26 16:31:42 -07:00
2026-05-04 19:21:41 -07:00
2025-11-18 23:18:35 -08:00
2026-05-04 19:21:41 -07:00
2025-10-23 20:10:12 -07:00
2025-11-18 23:18:35 -08:00
2025-12-23 14:48:50 -08:00
2026-05-04 19:14:41 -07:00
2026-05-04 19:14:41 -07:00
2026-07-02 21:11:34 -07:00
2026-06-14 13:54:49 -07:00
2025-12-30 12:40:59 -08:00
2026-07-02 21:11:34 -07:00
2026-05-19 17:34:51 -07:00
2026-07-02 21:11:34 -07:00
2026-07-02 21:27:58 -07:00
2025-10-29 13:43:27 -07:00
2026-07-02 21:11:41 -07:00
2026-07-02 21:11:34 -07:00
2026-05-19 17:35:08 -07:00
2026-02-07 13:27:47 -08:00
2026-07-02 21:27:58 -07:00
2026-07-02 21:11:34 -07:00
2026-07-02 21:11:34 -07:00
2025-08-21 08:28:07 -07:00
2026-07-02 21:11:41 -07:00
2026-07-02 21:27:58 -07:00
2026-02-12 23:11:41 -08:00
2026-03-27 23:15:01 -07:00
2026-03-16 12:58:26 -07:00
2025-08-21 08:28:07 -07:00
2026-06-16 16:29:30 -07:00
2026-06-16 16:29:30 -07:00
2026-04-03 16:04:27 -07:00
2026-07-02 13:25:04 -07:00
2026-06-22 22:19:24 -07:00
2025-10-24 01:45:22 -07:00
2026-05-05 11:26:08 -07:00
2026-07-02 09:14:54 -07:00
2026-05-19 17:35:44 -07:00
2026-07-02 09:14:54 -07:00
2026-01-07 13:06:08 -08:00
2026-02-03 11:55:12 -08:00
2026-06-03 00:28:56 -07:00
2026-05-05 11:26:08 -07:00
2026-02-07 13:27:47 -08:00
2026-05-19 16:03:45 -07:00
2026-05-10 09:39:05 -07:00
2026-05-13 10:48:58 -07:00
2026-01-07 13:06:08 -08:00
2026-06-11 21:56:16 -07:00
2026-04-26 16:31:42 -07:00
2026-01-22 16:56:35 -08:00
2026-06-04 15:33:03 -07:00
2026-03-04 12:52:09 -08:00
2026-05-10 12:08:06 -07:00
2026-05-10 14:55:59 -07:00
2026-06-14 00:16:14 -07:00
2026-05-10 13:34:25 -07:00
2026-05-21 09:35:42 -07:00
2026-06-05 12:41:18 -07:00
2026-06-22 22:19:24 -07:00
2026-06-14 00:16:14 -07:00
2026-06-24 19:36:42 -07:00
2026-05-21 09:35:42 -07:00
2026-07-02 13:25:04 -07:00
2026-06-11 21:56:16 -07:00
2026-06-11 21:56:16 -07:00
2026-07-04 00:41:57 -07:00
2026-01-17 18:40:48 -08:00
2026-05-21 14:05:16 -07:00
2026-03-11 02:28:34 -07:00
2026-04-02 15:59:52 -07:00
2026-05-21 15:48:47 -07:00
2026-07-05 20:19:20 -07:00
2026-07-02 21:11:34 -07:00
2026-06-11 21:56:16 -07:00
2026-04-14 21:52:49 -07:00
2026-07-01 18:45:17 -07:00
2026-07-01 18:45:17 -07:00
2025-07-19 00:49:56 -07:00
2026-02-08 20:06:32 -08:00
2026-07-05 20:19:20 -07:00
2026-07-02 21:11:34 -07:00
2026-05-08 21:35:27 -07:00
2026-07-02 21:11:34 -07:00
2025-07-18 22:25:58 -07:00
2026-07-02 21:11:34 -07:00
2026-06-22 07:52:01 -07:00
2026-06-09 00:48:38 -07:00
2026-03-28 13:24:11 -07:00
2026-06-03 00:12:28 -07:00
2026-06-03 00:12:28 -07:00
2026-06-08 01:12:07 -07:00
2026-05-31 00:13:36 -07:00
2026-06-11 21:56:16 -07:00
2026-06-01 20:01:30 -07:00
2026-07-02 13:25:04 -07:00
2026-06-11 21:56:16 -07:00
2026-06-11 21:56:16 -07:00
2026-03-28 13:24:11 -07:00
2026-02-16 13:59:13 -08:00
2025-12-09 10:24:35 -08:00
2026-06-16 14:02:41 -07:00
2026-03-09 11:54:32 -07:00
2026-05-18 19:44:19 -07:00
2026-07-02 21:11:41 -07:00
2026-04-03 16:04:27 -07:00
2026-04-25 23:06:37 -07:00
2025-11-18 23:18:35 -08:00
2026-01-07 13:06:08 -08:00
2026-03-30 12:11:30 -07:00
2026-06-24 21:38:21 -07:00
2026-05-05 19:14:44 -07:00
2026-05-05 19:14:44 -07:00
2026-02-23 22:59:53 -08:00
2026-04-02 15:59:09 -07:00
2026-04-02 17:37:05 -07:00
2026-06-24 20:14:26 -07:00
2026-06-24 16:24:45 -07:00
2026-05-19 14:24:25 -07:00
2026-05-19 14:24:25 -07:00
2026-01-07 13:06:08 -08:00
2026-06-11 21:56:16 -07:00
2026-06-11 21:56:16 -07:00
2026-05-13 10:48:58 -07:00
2026-05-13 10:48:58 -07:00
2026-05-13 10:48:58 -07:00
2024-07-04 11:00:41 -07:00
2026-07-02 21:11:41 -07:00
2026-04-26 16:31:42 -07:00
2026-05-13 09:24:59 -07:00
2026-05-20 10:13:33 -07:00
2026-05-04 22:10:49 -07:00
2026-03-06 15:22:39 -08:00
2026-05-04 22:10:49 -07:00
2026-06-23 01:25:32 -07:00
2026-06-23 01:25:32 -07:00