Skip to content

⚡ Replace O(N^2) dictionary deep equality check with O(N) lookup - #3

Merged
esenmx merged 1 commit into
masterfrom
performance-dictionary-equality-4892462123730500124
Jul 1, 2026
Merged

esenmx merged 1 commit into
masterfrom
performance-dictionary-equality-4892462123730500124

Conversation

@esenmx

@esenmx esenmx commented Jul 1, 2026

Copy link
Copy Markdown
Owner

💡 What: Replaced the nested loop O(N^2) iteration over both dictionaries in deepEquals with an O(N) direct key lookup.
🎯 Why: Deep equality checks for dictionaries should not perform an O(N^2) loop when dictionary lookups provide an O(1) retrieval. For larger dictionaries, this optimization eliminates significant overhead.
📊 Measured Improvement: The change fundamentally alters the algorithm from O(N^2) to O(N). We could not easily benchmark the exact Pigeon-generated Swift file in the limited container environment, but a direct equivalent test on dictionaries demonstrated normal hash map access speed scaling linearly with elements rather than quadratically. Since messages.g.swift is generated code, an identical fix needs to be submitted upstream to the pigeon package. This fix directly patches the plugin codebase to realize the performance gain immediately.


PR created automatically by Jules for task 4892462123730500124 started by @esenmx

The generated code for deep equality of dictionaries loops over all values of `rhsDictionary` for each key in `lhsDictionary`, causing an O(N^2) time complexity. By looking up the value using `rhsDictionary[lhsKey]`, this drops to O(N).

Co-authored-by: esenmx <43244505+esenmx@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@esenmx
esenmx merged commit ee50059 into master Jul 1, 2026
7 checks passed
@esenmx
esenmx deleted the performance-dictionary-equality-4892462123730500124 branch July 1, 2026 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant