SUZUKI Sosuke
de8c754c6a
perf(markdown): cache tag strings in React renderer (#26668)
## Summary
Cache frequently-used HTML tag strings (div, p, h1-h6, etc.) in
`GlobalObject` using `LazyProperty<JSGlobalObject, JSString>` instead of
creating new JSStrings on every React element creation in
`Bun.markdown.react()`.
## Changes
- Added `BunMarkdownTagStrings.h/.cpp` with 30 cached tag strings
- Modified `MarkdownObject.zig` to use cached strings via C API
- Integrated with `ZigGlobalObject` for proper GC visiting
## Benchmark Results
All benchmarks performed on Apple M4 Max with release builds.
### mitata Benchmark (Bun.markdown.react)
| Size | Main | Feature | Improvement |
|------|------|---------|-------------|
| small (121 chars) | 3.20 µs | 2.30 µs | **28% faster** |
| medium (1039 chars) | 15.09 µs | 14.02 µs | **7% faster** |
| large (20780 chars) | 288.48 µs | 267.14 µs | **7.4% faster** |
### Heap Profile
| Metric | Main | Feature | Improvement |
|--------|------|---------|-------------|
| Heap size | 500.7 KB | 469.7 KB | **6% reduction** |
| Object count | 12,000 | 10,315 | **14% reduction** |
| String count | 4,248 | 2,563 | **40% reduction** |
| String size | 97.1 KB | 65.8 KB | **32% reduction** |
### HTTP Request Benchmark (ab -n 10000 -c 20)
| Metric | Main | Feature | Improvement |
|--------|------|---------|-------------|
| Requests/sec | 7,710 | 8,174 | **6% faster** |
| Time/request | 2.59 ms | 2.45 ms | **5% faster** |
| p99 latency | 6 ms | 3 ms | **50% improvement** |
## Technical Details
The optimization uses JSC's `LazyProperty` pattern (similar to
`BunCommonStrings` and `BunHttp2CommonStrings`) to lazily initialize and
cache tag strings on first use. This avoids repeated
`bun.String.createUTF8ForJS` calls which allocate new JSStrings for the
same tag names on every markdown element.
---------
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2026-02-02 17:08:39 -08:00
..
2022-07-12 01:40:12 -07:00
2026-02-02 14:01:25 -08:00
2026-01-09 19:00:19 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2025-12-27 00:05:57 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2025-02-07 15:13:21 -08:00
2024-11-08 23:15:24 -08:00
2026-01-15 12:10:47 -08:00
2025-02-18 13:12:03 -08:00
2023-03-02 19:02:10 -08:00
2024-11-08 23:15:24 -08:00
2025-02-12 23:37:36 -08:00
2024-12-31 19:48:33 -08:00
2023-03-02 19:02:10 -08:00
2024-11-08 23:15:24 -08:00
2025-11-20 17:14:37 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2023-08-31 17:33:08 -07:00
2024-11-08 23:15:24 -08:00
2025-09-01 02:56:59 -07:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2025-02-16 00:42:05 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2025-07-10 00:10:43 -07:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2022-07-12 01:40:12 -07:00
2025-03-10 20:19:29 -07:00
2025-03-10 20:19:29 -07:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2025-06-03 03:34:35 -07:00
2024-11-08 23:15:24 -08:00
2022-12-06 14:18:25 -08:00
2022-12-06 14:18:25 -08:00
2023-11-06 03:51:49 -08:00
2024-11-08 23:15:24 -08:00
2025-12-29 20:02:18 -08:00
2025-12-29 20:02:18 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2022-07-12 01:40:12 -07:00
2026-01-29 12:38:05 -08:00
2026-02-02 17:08:39 -08:00
2024-11-08 23:15:24 -08:00
2025-01-03 13:57:46 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2025-08-01 14:35:04 -07:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2025-12-24 19:55:44 -08:00
2024-11-08 23:15:24 -08:00
2025-02-12 23:14:02 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2025-12-23 22:53:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2025-04-08 03:57:35 -07:00
2024-09-03 21:32:52 -07:00
2025-04-11 20:59:38 -07:00
2024-11-08 23:15:24 -08:00
2025-11-04 11:56:33 -08:00
2024-11-08 23:15:24 -08:00
2025-12-27 15:01:28 -08:00
2023-07-30 23:51:43 -07:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-09-03 21:32:52 -07:00
2024-09-03 21:32:52 -07:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-09-03 21:32:52 -07:00
2022-08-21 00:51:27 -07:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2025-07-07 23:08:12 -07:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2026-01-26 00:25:51 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2025-12-26 21:49:00 -08:00
2024-11-08 23:15:24 -08:00
2025-08-14 22:42:05 -07:00
2024-11-08 23:15:24 -08:00
2024-09-03 21:32:52 -07:00
2023-01-04 18:55:16 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2025-11-28 00:04:30 -08:00
2025-01-08 07:12:18 +00:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2026-01-16 16:12:23 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-12-24 04:20:24 -08:00