Skip to content

Conversation

@kamilkisiela
Copy link
Contributor

Single allocation of the vector. No more flat_map and collect - this way we remove the allocation and copying of intermediate vectors.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @kamilkisiela, 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 introduces a significant refactoring to the traverse_and_collect function, aiming to enhance its performance and memory efficiency. By transitioning from an iterative approach using flat_map and collect to a new recursive helper, the function now performs a single allocation for the result vector, drastically reducing unnecessary memory operations during data traversal.

Highlights

  • Performance Optimization & Refactoring: The traverse_and_collect function has been refactored to utilize a new recursive helper, traverse_and_collect_mut, which enables a single allocation of the result vector for improved efficiency.
  • Memory Efficiency: This change eliminates the use of flat_map and collect within the recursive traversal logic, thereby removing intermediate vector allocations and copying, leading to significant memory efficiency gains.
Using Gemini Code Assist

The 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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and 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 to provide feedback.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request refactors the traverse_and_collect function to use a recursive helper function, aiming to improve performance by reducing allocations and copying of intermediate vectors. The changes introduce a new helper function traverse_and_collect_mut to handle the recursion. I've provided feedback to improve readability by reducing nesting.

@ardatan ardatan force-pushed the no-preserve-order branch from 444ee6d to 3ac33e2 Compare June 27, 2025 10:33
@github-actions
Copy link

github-actions bot commented Jun 27, 2025

Federation Audit Results

188 tests  ±0   163 ✅  - 1   3s ⏱️ ±0s
 41 suites ±0     0 💤 ±0 
 41 files   ±0    25 ❌ +1 

For more details on these failures, see this check.

Results for commit 5f914d4. ± Comparison against base commit 3ac33e2.

♻️ This comment has been updated with latest results.

@github-actions
Copy link

github-actions bot commented Jun 27, 2025

TestsPassed ☑️SkippedFailed ❌️Time ⏱
federation-audit | abstract-types.xml18 ran13 ✅5 ❌517ms
federation-audit | child-type-mismatch.xml4 ran1 ✅3 ❌132ms
federation-audit | circular-reference-interface.xml2 ran1 ✅1 ❌49ms
federation-audit | complex-entity-call.xml1 ran1 ✅81ms
federation-audit | corrupted-supergraph-node-id.xml10 ran8 ✅2 ❌139ms
federation-audit | enum-intersection.xml5 ran5 ✅80ms
federation-audit | fed1-external-extends-resolvable.xml1 ran1 ✅25ms
federation-audit | fed1-external-extends.xml4 ran4 ✅61ms
federation-audit | fed1-external-extension.xml4 ran4 ✅67ms
federation-audit | fed2-external-extends.xml4 ran4 ✅65ms
federation-audit | fed2-external-extension.xml4 ran4 ✅66ms
federation-audit | include-skip.xml4 ran4 ✅82ms
federation-audit | input-object-intersection.xml3 ran3 ✅42ms
federation-audit | interface-object-with-requires.xml7 ran3 ✅4 ❌131ms
federation-audit | keys-mashup.xml1 ran1 ✅49ms
federation-audit | mutations.xml4 ran4 ✅80ms
federation-audit | mysterious-external.xml2 ran2 ✅42ms
federation-audit | nested-provides.xml2 ran2 ✅35ms
federation-audit | node.xml1 ran1 ✅26ms
federation-audit | non-resolvable-interface-object.xml7 ran7 ✅83ms
federation-audit | null-keys.xml1 ran1 ❌38ms
federation-audit | override-type-interface.xml4 ran3 ✅1 ❌68ms
federation-audit | override-with-requires.xml4 ran4 ✅94ms
federation-audit | parent-entity-call-complex.xml1 ran1 ✅35ms
federation-audit | parent-entity-call.xml1 ran1 ✅39ms
federation-audit | provides-on-interface.xml2 ran2 ✅46ms
federation-audit | provides-on-union.xml2 ran1 ✅1 ❌48ms
federation-audit | requires-interface.xml5 ran5 ✅90ms
federation-audit | requires-requires.xml5 ran5 ✅116ms
federation-audit | requires-with-argument.xml5 ran3 ✅2 ❌119ms
federation-audit | requires-with-fragments.xml6 ran6 ✅117ms
federation-audit | shared-root.xml2 ran2 ✅46ms
federation-audit | simple-entity-call.xml1 ran1 ✅24ms
federation-audit | simple-inaccessible.xml4 ran4 ✅55ms
federation-audit | simple-interface-object.xml13 ran8 ✅5 ❌217ms
federation-audit | simple-override.xml2 ran2 ✅38ms
federation-audit | simple-requires-provides.xml12 ran12 ✅168ms
federation-audit | typename.xml6 ran6 ✅101ms
federation-audit | unavailable-override.xml2 ran2 ✅36ms
federation-audit | union-interface-distributed.xml10 ran10 ✅114ms
federation-audit | union-intersection.xml12 ran12 ✅148ms

@github-actions
Copy link

github-actions bot commented Jun 27, 2025

k6-benchmark results

     ✓ response code was 200
     ✓ no graphql errors
     ✓ valid response structure

     █ setup

     checks.........................: 100.00% ✓ 7881      ✗ 0   
     data_received..................: 233 MB  7.7 MB/s
     data_sent......................: 3.1 MB  103 kB/s
     http_req_blocked...............: avg=77.64µs  min=1.49µs   med=3.5µs    max=5.42ms   p(90)=5.54µs   p(95)=7.5µs   
     http_req_connecting............: avg=69.64µs  min=0s       med=0s       max=5.38ms   p(90)=0s       p(95)=0s      
     http_req_duration..............: avg=123.53ms min=5.36ms   med=107.83ms max=507.95ms p(90)=187.87ms p(95)=235.85ms
       { expected_response:true }...: avg=123.53ms min=5.36ms   med=107.83ms max=507.95ms p(90)=187.87ms p(95)=235.85ms
     http_req_failed................: 0.00%   ✓ 0         ✗ 2647
     http_req_receiving.............: avg=1ms      min=33.69µs  med=56.15µs  max=119.52ms p(90)=561.69µs p(95)=1.43ms  
     http_req_sending...............: avg=340.25µs min=8.85µs   med=15.81µs  max=57.86ms  p(90)=74.96µs  p(95)=994.53µs
     http_req_tls_handshaking.......: avg=0s       min=0s       med=0s       max=0s       p(90)=0s       p(95)=0s      
     http_req_waiting...............: avg=122.19ms min=5.3ms    med=107ms    max=507.86ms p(90)=185.05ms p(95)=232.91ms
     http_reqs......................: 2647    87.464356/s
     iteration_duration.............: avg=572.84ms min=117.44ms med=560.65ms max=1.01s    p(90)=706.44ms p(95)=779.43ms
     iterations.....................: 2627    86.803499/s
     vus............................: 50      min=50      max=50
     vus_max........................: 50      min=50      max=50

Single allocation of the vector. No more `flat_map` and `collect` - this
way we remove the allocation and copying of intermediate vectors.
@ardatan ardatan force-pushed the kamil-traverse-impr branch from 7410b37 to 5f914d4 Compare June 27, 2025 10:40
@ardatan ardatan merged commit 042bf53 into no-preserve-order Jun 27, 2025
12 checks passed
@ardatan ardatan deleted the kamil-traverse-impr branch June 27, 2025 11:12
ardatan pushed a commit that referenced this pull request Jun 30, 2025
Single allocation of the vector. No more `flat_map` and `collect` - this
way we remove the allocation and copying of intermediate vectors.
ardatan pushed a commit that referenced this pull request Jul 1, 2025
Single allocation of the vector. No more `flat_map` and `collect` - this
way we remove the allocation and copying of intermediate vectors.
ardatan pushed a commit that referenced this pull request Jul 2, 2025
Single allocation of the vector. No more `flat_map` and `collect` - this
way we remove the allocation and copying of intermediate vectors.
ardatan pushed a commit that referenced this pull request Jul 2, 2025
Single allocation of the vector. No more `flat_map` and `collect` - this
way we remove the allocation and copying of intermediate vectors.
ardatan pushed a commit that referenced this pull request Jul 3, 2025
Single allocation of the vector. No more `flat_map` and `collect` - this
way we remove the allocation and copying of intermediate vectors.
ardatan pushed a commit that referenced this pull request Jul 8, 2025
Single allocation of the vector. No more `flat_map` and `collect` - this
way we remove the allocation and copying of intermediate vectors.
ardatan pushed a commit that referenced this pull request Jul 9, 2025
Single allocation of the vector. No more `flat_map` and `collect` - this
way we remove the allocation and copying of intermediate vectors.
ardatan pushed a commit that referenced this pull request Jul 16, 2025
Single allocation of the vector. No more `flat_map` and `collect` - this
way we remove the allocation and copying of intermediate vectors.
ardatan pushed a commit that referenced this pull request Jul 17, 2025
Single allocation of the vector. No more `flat_map` and `collect` - this
way we remove the allocation and copying of intermediate vectors.
ardatan pushed a commit that referenced this pull request Jul 18, 2025
Single allocation of the vector. No more `flat_map` and `collect` - this
way we remove the allocation and copying of intermediate vectors.
ardatan pushed a commit that referenced this pull request Jul 21, 2025
Single allocation of the vector. No more `flat_map` and `collect` - this
way we remove the allocation and copying of intermediate vectors.
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.

2 participants