Repository navigation
fix: batch large member unions - #1077
Conversation
Code Review SummaryPerformance Improvements ✅The changes introduce a batch union operation ( Potential Issues
Code Quality Observations
Security ConcernsNone identified. The changes are purely type system optimizations. Overall AssessmentThe refactoring is well-motivated and correctly preserves semantics in most cases. The |
There was a problem hiding this comment.
Code Review
This pull request introduces a centralized TypeOps::union_all utility to handle union operations across the codebase, replacing manual iterative TypeOps::Union.apply calls. This change improves performance and consistency in type inference, particularly for large tables and complex union types. It also includes a new test case for large table dynamic string keys to ensure stability. I have provided feedback on improving the efficiency of the union_all implementation, correcting a missing flag in the structural union check, and ensuring consistent use of the new utility in member inference.
Broad dynamic keys can match hundreds of table members. Collect matching member types and fold the union once instead of repeatedly unioning a growing result. Keep the batch helper on the same semantic path as repeated `Union.apply`, including callable canonicalization, and use the structural fast path only when no pairwise union rule can change the result. Fixes EmmyLuaLs#1075 Assisted-by: Codex
734af10 to
e6f1167
Compare
|
This is a script someone shared with me. I tested it with different versions and found that even after your fix, its loading performance is only one-third of what it was in version 0.21.0.(0.22.0 will stuck loading) |
|
The script above has too much content and isn't suitable for testing. I tested the script from the original issue, and the performance ratio is still about the same — roughly a threefold difference. |
|
We may need to introduce a performance monitoring system, similar to Flame Graph, that can precisely observe the call duration of each function. |
|
This PR should specifically fix the slowdown from the scripts in #1075 , it goes from hanging to 1.6s. I can look at https://github.com/user-attachments/files/27706685/scripts.zip (assuming it's different), but that may be slow for a different reason. As we improve flow and type-checking to infer more types, slowdown is expected since there will be significantly less |
|
Summary
TypeOps::union_allUnion.applyFixes #1075
Validation
cargo test -p emmylua_code_analysis test_union_all_keeps_union_semantics -- --nocapturecargo test -p emmylua_code_analysis test_issue_1075_large_table_dynamic_string_key -- --nocapturecargo test -p emmylua_code_analysis