perf(bridge): optimize slice and map reflection bindings#166
Conversation
- optimize `bindSlice` with a fast path for `[]byte` and `[N]byte` to map directly to JS `Uint8Array`, drastically reducing generic interface slice conversion overhead. Added `bufCopy` check for safe memory boundaries. - optimize `bindMap` by replacing `v.MapKeys()` slice allocation with `v.MapRange()` iteration, and mapping numeric primitives directly to strings using `strconv` instead of `fmt.Sprint()` to avoid interface boxing. - benchmarks showed `bindSlice` for 1MB `[]byte` dropping from ~66.8M ns/op to ~971K ns/op, and `bindMap` for `int` dropping from ~717K ns/op to ~632K ns/op. Co-authored-by: repyh <63894915+repyh@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (10)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthroughThis PR adds a byte-slice fast path in Go→JS binding (ArrayBuffer → Uint8Array fallback), improves bindMap iteration and numeric key formatting using strconv, and updates import-generation/installer logic to dedupe and gate external imports plus pins gin in an example. ChangesBinding Layer Optimization
Import generation, installer, and dependency fixes
Sequence DiagramsequenceDiagram
participant Caller as Binding Caller
participant bindSlice
participant Uint8Array as JS Uint8Array
participant bindMap
participant strconv as strconv
participant JSObj as JS Object
Caller->>bindSlice: byte slice value
bindSlice->>bindSlice: copy bytes to ArrayBuffer
bindSlice->>Uint8Array: vm.Get("Uint8Array")
alt Uint8Array available
bindSlice->>Uint8Array: vm.New(...ArrayBuffer)
alt Success
Uint8Array-->>bindSlice: Uint8Array instance
else Failure
bindSlice-->>Caller: fallback to ArrayBuffer
end
else Unavailable
bindSlice-->>Caller: return ArrayBuffer
end
Caller->>bindMap: map[K]V
bindMap->>bindMap: MapRange() iterator
loop per map entry
bindMap->>bindMap: inspect key kind
alt key is signed int
bindMap->>strconv: FormatInt(key)
else key is unsigned/uintptr
bindMap->>strconv: FormatUint(key)
else key is string
bindMap->>bindMap: key.String()
else
bindMap->>bindMap: fmt.Sprint(key.Interface())
end
bindMap->>JSObj: set formattedKey:boundValue
end
bindMap-->>Caller: JS object
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…al modules When `typego build` or `typego run` fails to inspect an external module (e.g. due to go version incompatibilities), it currently skips generating the virtual module but still adds the standard go import in the `main.go` file. This causes the Go compiler to throw an "imported and not used" error. This patch updates `build.go`, `run.go`, and `install.go` to explicitly keep track of which modules were successfully inspected. Only successfully inspected modules are added to the final import block in the scaffolded Go shim, and we avoid inserting imports that are missing their corresponding JS virtual module. Co-authored-by: repyh <63894915+repyh@users.noreply.github.com>
Optimization audit implementation targeting unnecessary allocations and interface boxing in
bridge/core/reflection.go.PR created automatically by Jules for task 8095066981084513861 started by @repyh
Summary by CodeRabbit
Refactor
Bug Fixes
Chores