perf(pi-extension): exact .ts specifiers cut Pi load from 43.5ms to 15ms#1106
Merged
backnotprop merged 2 commits intoJul 22, 2026
Merged
Conversation
dca123
force-pushed
the
perf/pi-extension-ts-specifiers
branch
from
July 22, 2026 02:40
cf8fdf9 to
347ac0d
Compare
dca123
marked this pull request as ready for review
July 22, 2026 04:19
The Pi extension is distributed and executed as raw TypeScript through Pi's jiti loader. Phantom .js paths force jiti through its last-resort fallback, while extensionless paths still require probing. Exact .ts paths avoid both and match the files that actually ship. - rewrite relative .js and extensionless specifiers in hand-written sources (the existing noEmit bundler tsconfig permits .ts imports) - make vendor.sh emit .ts in explicit rewrite rules and normalize both source styles across verbatim-copied generated modules - guard hand-written and generated sources against either inexact form Extension module import: 43.5ms -> 15ms median (PI_TIMING, n=12 interleaved). bun test: 73/73 (pi-extension), 456/456 (server); all seven TypeScript project checks and the packed-artifact audit pass.
dca123
force-pushed
the
perf/pi-extension-ts-specifiers
branch
from
July 22, 2026 04:23
347ac0d to
e20eef8
Compare
dca123
marked this pull request as draft
July 22, 2026 04:24
dca123
marked this pull request as ready for review
July 22, 2026 05:07
…t-specifier conflict, keep exact .ts)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The Pi extension is distributed and executed as raw TypeScript (
pi.extensions→index.ts,noEmit) — but its relative import specifiers mix phantom.jspaths with extensionless paths. The former name files that never exist in this package; both require jiti to probe instead of resolving the exact file.Pi's loader (jiti) supports the
.js→.tsremap, but only as its last-resort fallback — after two full ESM resolution cascades and three constructedERR_MODULE_NOT_FOUNDs per import:esmResolve, same file"./config.js"(phantom)"./config.ts"(real file)Multiplied across the eager import graph it cost me around that's ~26 ms of every Pi session start.
This never shows up in development because Bun does the same remap natively at no cost.
startup.test.tsguards the eager-graph shape, but under the one runtime that doesn't exhibit the cost.Measured result
Extension module import (
PI_TIMING=1, n=12 interleaved runs, same machine):main(.js+ extensionless).ts)What changed
.jsand extensionless specifiers to exact.tspaths. The tsconfig already fully permits this (moduleResolution: "bundler",noEmit,allowImportingTsExtensions) — zero config changes.vendor.sh: rewrite rules now emit.ts, plus a final normalization pass overgenerated/for both.jsand extensionless source styles — the monorepo conventions are untouched. It covers import/re-export, dynamic import, and side-effect import forms while leaving bare and explicit non-TypeScript specifiers alone.import-specifiers.test.ts: guards the invariant so future contributions in either style stay correct.Validation
bun test— 73/73 (apps/pi-extension), 456/456 (packages/server, which imports these files).tstargets existgenerated/and the pi-extension sources are consumed only by this package's runtimes (jiti/Bun); the hook, OpenCode, VS Code, and web builds importpackages/*directly and see no changed bytes