-
Notifications
You must be signed in to change notification settings - Fork 247
Fix profiler benchmarking sending unserializable data #6985
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
utility for converting unserializable data to serializable data that can be sent across the sim-ui boundary
📝 WalkthroughWalkthroughThree files updated to add Lua benchmark infrastructure and serialization utilities: a new benchmark module measuring ArmyBrains value-access performance across six different patterns, a serialization helper function with cycle detection for UI-sim boundary data transfer, and Profiler refactored to use the new serialization approach instead of in-place upvalue sanitization. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: defaults Review profile: CHILL Plan: Pro 📒 Files selected for processing (3)
🧰 Additional context used🧬 Code graph analysis (2)lua/sim/Profiler.lua (2)
lua/benchmarks/value-access.lua (1)
🔇 Additional comments (7)
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 |
| b._seenTableId = tostring(_t) | ||
| end | ||
| -- format makes it easy to find in repr output | ||
| return '_seenTableId = "' .. b._seenTableId .. '"' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the table ID never changes, why dirty the table with an unoriginal field to store the seen table ID? We could use tostring every time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The table ID should change after being copied across the sim-ui boundary, so the table tostring won't give useful information.
An alternative to not dirty the table would be to return an extra table documenting all the references that were converted to strings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But you already are using tostring; as you've written it right now, if a table's _seenTableId field exists, it is always filled with tostring applied to that table. You gave a fine reason to use tostring in your previous reply, so I'm not sure why you're saying it doesn't give any useful information here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if a table's _seenTableId field exists, it is always filled with tostring applied to that table
This is not true because the table is presumedly copied across sim-ui, where the field will be filled with tostring applied to the old table before the copying. When you read the copied table you need the old tostring ID to rebuild cyclic references.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see - I thought _seenTableId was only being used for serialization (the return value on line 618). But you also want to leave it as a marker as part of the data in case you want to deserialize it (which we haven't set up) rather than only using the data we pass for textual purposes.
Issue
The profiler can send unserializable data through the upvalues provided in function debug information. The code handles basic cases with functions and cfunctions, but not everything. Tables are the main issue since they're easy to find reasons to upvalue and they can have cyclic references (the engine recursively serializes without cycle protection, so it causes a stack overflow) and they can reference unserializable data of a wide variety of types.
Description of the proposed changes
utilities.luain theSERIALIZABLE_TYPEStableSerializableDeepCopyto convert unserializable values/tables to serializable versions._c_objects)/other objects (threads).Testing done on the proposed changes
The benchmark loads when you navigate to its file in the profiler and select one of the local/upvalue lua functions (this means the ArmyBrains table was serialized successfully).
An example command:
Checklist
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.