SUZUKI Sosuke
e29e830a25
perf(path): use pre-built Structure for path.parse() result objects (#26865)
## Summary
Optimize `path.parse()` by caching a pre-built JSC Structure for the
result object. Instead of creating a new empty object and performing 5
`putDirect` calls (each triggering a Structure transition), we now use
`constructEmptyObject` with the cached Structure and write values
directly via `putDirectOffset`.
## What changed
- **`ZigGlobalObject.h/cpp`**: Added `m_pathParsedObjectStructure` as a
`LazyPropertyOfGlobalObject<Structure>` with fixed property offsets for
`{root, dir, base, ext, name}`.
- **`Path.cpp`**: Added `PathParsedObject__create` extern "C" factory
function that constructs the object using the pre-built Structure and
`putDirectOffset`.
- **`path.zig`**: Replaced `toJSObject()` implementation to call the C++
factory function instead of `createEmptyObject` + 5x `.put()`.
- **`bench/snippets/path-parse.mjs`**: Added benchmark for
`path.parse()`.
This follows the same pattern used by `JSSocketAddressDTO` and
`m_jsonlParseResultStructure`.
## Benchmark results (Apple M4 Max)
| Benchmark | Before (1.3.9) | After | Speedup |
|---|---|---|---|
| `posix.parse("/home/user/dir/file.txt")` | 266.71 ns | 119.62 ns |
**2.23x** |
| `posix.parse("/home/user/dir/")` | 239.10 ns | 91.46 ns | **2.61x** |
| `posix.parse("file.txt")` | 232.55 ns | 89.20 ns | **2.61x** |
| `posix.parse("/root")` | 246.75 ns | 92.68 ns | **2.66x** |
| `posix.parse("")` | 152.19 ns | 20.72 ns | **7.34x** |
| `win32.parse("/home/user/dir/file.txt")` | 260.08 ns | 118.12 ns |
**2.20x** |
| `win32.parse("/home/user/dir/")` | 234.35 ns | 93.47 ns | **2.51x** |
| `win32.parse("file.txt")` | 224.19 ns | 80.56 ns | **2.78x** |
| `win32.parse("/root")` | 241.20 ns | 88.23 ns | **2.73x** |
| `win32.parse("")` | 160.39 ns | 24.20 ns | **6.63x** |
**~2.2x–2.8x faster** for typical paths, **~7x faster** for empty
strings.
## GC Safety
- `LazyPropertyOfGlobalObject<Structure>` is automatically visited via
`FOR_EACH_GLOBALOBJECT_GC_MEMBER`.
- JSValues created by `createUTF8ForJS` are protected by JSC's
conservative stack scanning during the factory function call.
## Test
All 116 existing path tests pass (`bun bd test test/js/node/path/`).
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2026-02-10 22:32:08 -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
2026-02-09 01:46:33 -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
2026-02-10 22:32:08 -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
2026-02-09 21:54:41 -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