Refactor gc#41
Conversation
Reasoning DetailsWe need to review the provided code changes. The diff shows several files modified and new files added in a Rust project (luars). The changes involve introducing a paged pool allocator (PagedPool, Pooled) and a table allocator (TableAllocHandle), and modifying various types to use these new allocation strategies instead of Box. The GcObjectOwner enum now uses Pooled instead of Box for most variants except Thread (still Box). The object_allocator creates objects via pools. The string_interner now takes a PagedPool parameter. The native_table uses TableAllocHandle for allocating array and hash memory. Also, a clippy allow annotation added.Potential issues to check:
Overall, the changes introduce custom pooling for GC objects and table memory. This is likely for performance (reducing allocation overhead, better cache locality). The code seems well-implemented with attention to safety. However, there are a few things to double-check:
Potential improvement: In One subtle issue: In Another thing: In Now, regarding the GC: The GC likely walks through GcObjectOwner variants and needs to mark/release objects. With Box, it used to drop the Box when the object is collected. Now with Pooled, the Pooled will be dropped, which returns the slot to the pool. That's good for reuse. But the drop order: When GC collects an object, it will drop the GcObjectOwner, which drops the Pooled, which returns the slot. But the pool itself is owned by ObjectAllocator, which lives longer (the Lua state). That's fine. Potential memory leak: If the GC never collects, the Pooled objects remain, but that's fine. The pool pages are never freed until the pool is dropped. That's intended for reuse. One potential issue: The Now, check for any obvious unsoundness: In However, in the One more thing: The Overall, the changes appear sound and well-structured. However, I should note any potential issues in the review answer. Review checklist items:
Thus, the review will note that the changes are generally good, but might point out for the reviewer to consider using NonNull in free lists instead of usize, and ensure that Box consistency is intentional. Also, check that the Pooled type is not accidentally Clone or Copy (it is not, but ensure). Also, note that the Given the instructions: "Identify potential issues such as code style violations, logical errors, security vulnerabilities, and provide improvement suggestions. Clearly list the problems and recommendations in a concise manner." I'll produce a list of observations and recommendations. Code Review FindingsOverviewThis PR introduces custom pool-based allocators ( Potential Issues & Recommendations1.
|
No description provided.