perf: tagged-union packed format eliminates serialize for scalar values#55
perf: tagged-union packed format eliminates serialize for scalar values#55
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the performance of Judy arrays by introducing a specialized packed format for scalar values. Instead of serializing and unserializing every value, common scalar types are now stored directly within a tagged union, leading to faster read and write operations. Complex types gracefully fall back to the existing serialization mechanism, ensuring compatibility while providing a substantial speed boost for frequently used data types. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a significant performance improvement for INT_TO_PACKED Judy arrays by creating a fast path for scalar values, avoiding costly serialization and unserialization. The new implementation uses a tagged union to store scalars directly. The changes are well-implemented and accompanied by good test coverage for both the new fast path and the existing fallback mechanism. I have a couple of suggestions to improve maintainability and fix a potential memory issue in an edge case.
Test Results
Benchmark Summary (Judy vs PHP Array)Ratio = Judy / Array. Bold = Judy wins (≤0.95x). Plain = Array is faster/smaller. Time (Write / Read) — Linux
Memory — Linux
Time (Write / Read) — Windows
Memory — Windows
Raw benchmark dataWrite Time — Linux
Read Time — Linux
Memory — Linux
Write Time — Windows
Read Time — Windows
Memory — Windows
Batch & Set Operations BenchmarksBenchmarks for Batch Operations — PHP 8.5 (Linux)Set Operations — PHP 8.5 (Linux)All-Types Comparison BenchmarkSide-by-side comparison of all six Judy types and native PHP array (50K elements, 3 iterations, Linux only). All-Types Benchmark — PHP 8.5 (Linux) |
Replace the opaque serialize-everything judy_packed_value with a tagged union that stores long/double/bool/null/string directly (tags 0–5), falling back to php_var_serialize only for arrays and objects (tag 255). This avoids the serialize/unserialize overhead for the common case where INT_TO_PACKED stores scalar values. Breaking: old serialized INT_TO_PACKED data is incompatible.
6780d56 to
91b5628
Compare
|
Rebased onto current Both Gemini review items were addressed in
|
Summary
php_var_serialize/php_var_unserializeinjudy_pack_value/judy_unpack_valuewith a direct tagged-union struct (judy_packed_value) for the five common scalar types: long, double, true, false, nulluint8_t tag+ union to store values inline; only non-scalar zvals fall back to the serialization path (tag 255)sliceto usejudy_packed_value_size()+memcpyinstead of unpacking and repacking each valueTest plan
tests/packed_scalar_fastpath_001.phpt— long/double/bool/null round-trip through the fastpathtests/packed_complex_fallback_001.phpt— arrays/objects fall back to serialize correctly