perf: optimize bindSlice and bindMap allocations#169
Conversation
Optimizes the `bindSlice` and `bindMap` functions in `bridge/core/reflection.go` to eliminate significant memory allocations and reduce boxing overhead: - `bindSlice`: Avoids copying byte slices element-by-element (which creates 1 interface per byte) by detecting `[]byte` and using zero-copy extraction with `v.Bytes()`. The extracted data is then explicitly copied for memory safety and wrapped inside a JS `Uint8Array`. Benchmark time dropped from ~68.8M ns/op to ~1.0M ns/op for 1MB buffers. - `bindMap`: Prevents allocating a slice of keys by replacing `v.MapKeys()` with a `v.MapRange()` iterator. It also leverages `strconv` instead of `fmt.Sprint` for primitive numeric keys to sidestep interface boxing latency. Benchmark time improved from ~766k ns/op down to ~656k 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 selected for processing (1)
📝 WalkthroughWalkthroughThis PR optimizes Go→JavaScript reflection bindings in ChangesReflection Binding Performance
🎯 2 (Simple) | ⏱️ ~12 minutes
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
These optimizations remove substantial garbage collection and memory overhead from TypeGo's core reflection bridge when handling large buffers and map structures.
PR created automatically by Jules for task 17481360139873684640 started by @repyh
Summary by CodeRabbit