Skip to content

BE-514: HashQL: implement iterative adjustment passes in placement solver#8635

Draft
indietyp wants to merge 1 commit intobm/be-500-hashql-forward-substitution-unified-param-resolutionfrom
bm/be-514-hashql-solver-iterate-forwardbackward-passes-to-convergence
Draft

BE-514: HashQL: implement iterative adjustment passes in placement solver#8635
indietyp wants to merge 1 commit intobm/be-500-hashql-forward-substitution-unified-param-resolutionfrom
bm/be-514-hashql-solver-iterate-forwardbackward-passes-to-convergence

Conversation

@indietyp
Copy link
Copy Markdown
Member

🌟 What is the purpose of this PR?

This PR enhances the placement solver in the MIR dataflow analysis framework by implementing iterative adjustment passes that alternate direction until convergence. Instead of a simple two-pass approach (forward then backward), the solver now continues refining assignments in alternating directions until no further improvements are found, converging to a better local minimum.

🔍 What does this change?

  • Adds a reverse() method to the Direction enum to toggle between Forward and Backward directions
  • Replaces the single backward refinement pass with iterative adjustment passes that alternate direction until convergence
  • Modifies adjust_trivial() and adjust_cyclic() methods to return boolean flags indicating whether assignments changed
  • Introduces a new run_adjustment() method that processes regions in the specified direction and tracks changes
  • Updates documentation to reflect the new iterative convergence approach rather than the previous two-pass strategy

Pre-Merge Checklist 🚀

🚢 Has this modified a publishable library?

This PR:

  • does not modify any publishable blocks or libraries, or modifications do not need publishing

📜 Does this require a change to the docs?

The changes in this PR:

  • are internal and do not require a docs change

🕸️ Does this require a change to the Turbo Graph?

The changes in this PR:

  • do not affect the execution graph

🛡 What tests cover this?

  • Existing placement solver tests continue to validate the functionality
  • Updated test in backward_pass_keeps_assignment_when_csp_fails() to handle the new return signature

❓ How to test this?

  1. Checkout the branch
  2. Run the existing MIR placement solver tests
  3. Confirm that placement optimization still works correctly with the new iterative approach

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 16, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
hash Ready Ready Preview, Comment Apr 16, 2026 9:51am
3 Skipped Deployments
Project Deployment Actions Updated (UTC)
hashdotdesign Ignored Ignored Preview Apr 16, 2026 9:51am
hashdotdesign-tokens Ignored Ignored Preview Apr 16, 2026 9:51am
petrinaut Skipped Skipped Apr 16, 2026 9:51am

Copy link
Copy Markdown
Member Author

remind me to add a test case for the reason this fails before merging:

3-node chain A → B → C:

 - Unary costs: u_A(0)=3, u_A(1)=0; u_B(0)=u_B(1)=0; u_C(0)=0
 - Edge costs: A–B mismatch cost 2, B–C mismatch cost 1
 - Start from labeling 000

Backward sweep (sinks first): C stays 0, B stays 0 (given A=0, C=0), A switches to 1 (given B=0). Final: 1,0,0.

But changing only B from 0 to 1 lowers total cost — so the result after one sweep is not a 1-opt local minimum.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 16, 2026

Codecov Report

❌ Patch coverage is 97.36842% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 71.72%. Comparing base (77eb677) to head (60563b3).

Files with missing lines Patch % Lines
...shql/mir/src/pass/execution/placement/solve/mod.rs 96.87% 1 Missing ⚠️
Additional details and impacted files
@@                                       Coverage Diff                                       @@
##           bm/be-500-hashql-forward-substitution-unified-param-resolution    #8635   +/-   ##
===============================================================================================
  Coverage                                                           71.71%   71.72%           
===============================================================================================
  Files                                                                1047     1047           
  Lines                                                              104282   104301   +19     
  Branches                                                             4665     4666    +1     
===============================================================================================
+ Hits                                                                74791    74810   +19     
  Misses                                                              28716    28716           
  Partials                                                              775      775           
Flag Coverage Δ
apps.hash-ai-worker-ts 1.40% <ø> (ø)
apps.hash-api 0.00% <ø> (ø)
local.hash-graph-sdk 9.63% <ø> (ø)
local.hash-isomorphic-utils 0.00% <ø> (ø)
rust.hash-graph-api 2.52% <ø> (ø)
rust.hashql-compiletest 28.31% <ø> (ø)
rust.hashql-mir 91.69% <97.36%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Apr 16, 2026

Merging this PR will not alter performance

✅ 24 untouched benchmarks
⏩ 56 skipped benchmarks1


Comparing bm/be-514-hashql-solver-iterate-forwardbackward-passes-to-convergence (60563b3) with bm/be-500-hashql-forward-substitution-unified-param-resolution (77eb677)

Open in CodSpeed

Footnotes

  1. 56 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@github-actions
Copy link
Copy Markdown
Contributor

Benchmark results

@rust/hash-graph-benches – Integrations

policy_resolution_large

Function Value Mean Flame graphs
resolve_policies_for_actor user: empty, selectivity: high, policies: 2002 $$28.5 \mathrm{ms} \pm 181 \mathrm{μs}\left({\color{gray}1.65 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: empty, selectivity: low, policies: 1 $$3.56 \mathrm{ms} \pm 26.0 \mathrm{μs}\left({\color{gray}2.66 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: empty, selectivity: medium, policies: 1001 $$14.0 \mathrm{ms} \pm 88.3 \mathrm{μs}\left({\color{red}11.2 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: seeded, selectivity: high, policies: 3314 $$44.4 \mathrm{ms} \pm 341 \mathrm{μs}\left({\color{gray}2.69 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: seeded, selectivity: low, policies: 1 $$15.0 \mathrm{ms} \pm 127 \mathrm{μs}\left({\color{gray}1.55 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: seeded, selectivity: medium, policies: 1526 $$25.0 \mathrm{ms} \pm 199 \mathrm{μs}\left({\color{gray}1.62 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: system, selectivity: high, policies: 2078 $$29.1 \mathrm{ms} \pm 173 \mathrm{μs}\left({\color{gray}0.975 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: system, selectivity: low, policies: 1 $$3.88 \mathrm{ms} \pm 23.1 \mathrm{μs}\left({\color{gray}1.83 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: system, selectivity: medium, policies: 1033 $$14.9 \mathrm{ms} \pm 102 \mathrm{μs}\left({\color{gray}3.62 \mathrm{\%}}\right) $$ Flame Graph

policy_resolution_medium

Function Value Mean Flame graphs
resolve_policies_for_actor user: empty, selectivity: high, policies: 102 $$3.87 \mathrm{ms} \pm 21.3 \mathrm{μs}\left({\color{gray}1.15 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: empty, selectivity: low, policies: 1 $$3.13 \mathrm{ms} \pm 23.8 \mathrm{μs}\left({\color{gray}3.96 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: empty, selectivity: medium, policies: 51 $$3.42 \mathrm{ms} \pm 19.4 \mathrm{μs}\left({\color{gray}-0.015 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: seeded, selectivity: high, policies: 269 $$5.35 \mathrm{ms} \pm 47.7 \mathrm{μs}\left({\color{gray}2.68 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: seeded, selectivity: low, policies: 1 $$3.62 \mathrm{ms} \pm 21.2 \mathrm{μs}\left({\color{gray}1.69 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: seeded, selectivity: medium, policies: 107 $$4.31 \mathrm{ms} \pm 24.1 \mathrm{μs}\left({\color{gray}2.90 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: system, selectivity: high, policies: 133 $$4.48 \mathrm{ms} \pm 27.8 \mathrm{μs}\left({\color{gray}0.231 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: system, selectivity: low, policies: 1 $$3.47 \mathrm{ms} \pm 19.3 \mathrm{μs}\left({\color{gray}-0.330 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: system, selectivity: medium, policies: 63 $$4.16 \mathrm{ms} \pm 29.0 \mathrm{μs}\left({\color{gray}1.76 \mathrm{\%}}\right) $$ Flame Graph

policy_resolution_none

Function Value Mean Flame graphs
resolve_policies_for_actor user: empty, selectivity: high, policies: 2 $$2.69 \mathrm{ms} \pm 15.1 \mathrm{μs}\left({\color{gray}2.54 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: empty, selectivity: low, policies: 1 $$2.56 \mathrm{ms} \pm 14.7 \mathrm{μs}\left({\color{gray}1.52 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: empty, selectivity: medium, policies: 1 $$2.67 \mathrm{ms} \pm 12.9 \mathrm{μs}\left({\color{gray}3.43 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: system, selectivity: high, policies: 8 $$2.95 \mathrm{ms} \pm 15.2 \mathrm{μs}\left({\color{gray}2.35 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: system, selectivity: low, policies: 1 $$2.78 \mathrm{ms} \pm 17.2 \mathrm{μs}\left({\color{gray}3.64 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: system, selectivity: medium, policies: 3 $$2.95 \mathrm{ms} \pm 16.4 \mathrm{μs}\left({\color{gray}3.89 \mathrm{\%}}\right) $$ Flame Graph

policy_resolution_small

Function Value Mean Flame graphs
resolve_policies_for_actor user: empty, selectivity: high, policies: 52 $$3.12 \mathrm{ms} \pm 20.4 \mathrm{μs}\left({\color{gray}2.00 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: empty, selectivity: low, policies: 1 $$2.74 \mathrm{ms} \pm 13.1 \mathrm{μs}\left({\color{gray}-2.139 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: empty, selectivity: medium, policies: 25 $$3.09 \mathrm{ms} \pm 15.8 \mathrm{μs}\left({\color{gray}1.71 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: seeded, selectivity: high, policies: 94 $$3.45 \mathrm{ms} \pm 15.7 \mathrm{μs}\left({\color{gray}-1.284 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: seeded, selectivity: low, policies: 1 $$2.98 \mathrm{ms} \pm 15.8 \mathrm{μs}\left({\color{gray}-1.542 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: seeded, selectivity: medium, policies: 26 $$3.29 \mathrm{ms} \pm 18.0 \mathrm{μs}\left({\color{gray}-1.296 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: system, selectivity: high, policies: 66 $$3.47 \mathrm{ms} \pm 24.0 \mathrm{μs}\left({\color{gray}2.17 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: system, selectivity: low, policies: 1 $$3.05 \mathrm{ms} \pm 18.0 \mathrm{μs}\left({\color{gray}1.54 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: system, selectivity: medium, policies: 29 $$3.38 \mathrm{ms} \pm 18.3 \mathrm{μs}\left({\color{gray}1.39 \mathrm{\%}}\right) $$ Flame Graph

read_scaling_complete

Function Value Mean Flame graphs
entity_by_id;one_depth 1 entities $$55.2 \mathrm{ms} \pm 306 \mathrm{μs}\left({\color{gray}-2.261 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id;one_depth 10 entities $$47.0 \mathrm{ms} \pm 217 \mathrm{μs}\left({\color{gray}-0.856 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id;one_depth 25 entities $$52.4 \mathrm{ms} \pm 483 \mathrm{μs}\left({\color{gray}-0.509 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id;one_depth 5 entities $$45.7 \mathrm{ms} \pm 255 \mathrm{μs}\left({\color{gray}-1.137 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id;one_depth 50 entities $$64.3 \mathrm{ms} \pm 392 \mathrm{μs}\left({\color{gray}0.409 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id;two_depth 1 entities $$62.7 \mathrm{ms} \pm 330 \mathrm{μs}\left({\color{gray}-1.695 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id;two_depth 10 entities $$56.9 \mathrm{ms} \pm 345 \mathrm{μs}\left({\color{gray}-1.657 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id;two_depth 25 entities $$104 \mathrm{ms} \pm 569 \mathrm{μs}\left({\color{gray}-2.098 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id;two_depth 5 entities $$47.2 \mathrm{ms} \pm 204 \mathrm{μs}\left({\color{gray}-1.783 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id;two_depth 50 entities $$298 \mathrm{ms} \pm 705 \mathrm{μs}\left({\color{red}7.32 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id;zero_depth 1 entities $$19.6 \mathrm{ms} \pm 117 \mathrm{μs}\left({\color{gray}-1.954 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id;zero_depth 10 entities $$20.2 \mathrm{ms} \pm 90.3 \mathrm{μs}\left({\color{gray}-2.922 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id;zero_depth 25 entities $$20.4 \mathrm{ms} \pm 108 \mathrm{μs}\left({\color{gray}-1.612 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id;zero_depth 5 entities $$19.5 \mathrm{ms} \pm 109 \mathrm{μs}\left({\color{gray}-3.150 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id;zero_depth 50 entities $$25.1 \mathrm{ms} \pm 132 \mathrm{μs}\left({\color{gray}-0.192 \mathrm{\%}}\right) $$ Flame Graph

read_scaling_linkless

Function Value Mean Flame graphs
entity_by_id 1 entities $$19.8 \mathrm{ms} \pm 125 \mathrm{μs}\left({\color{gray}1.13 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 10 entities $$20.1 \mathrm{ms} \pm 139 \mathrm{μs}\left({\color{gray}0.510 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 100 entities $$20.1 \mathrm{ms} \pm 112 \mathrm{μs}\left({\color{gray}1.25 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 1000 entities $$20.8 \mathrm{ms} \pm 124 \mathrm{μs}\left({\color{gray}1.24 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 10000 entities $$27.3 \mathrm{ms} \pm 226 \mathrm{μs}\left({\color{gray}2.61 \mathrm{\%}}\right) $$ Flame Graph

representative_read_entity

Function Value Mean Flame graphs
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/block/v/1 $$36.5 \mathrm{ms} \pm 376 \mathrm{μs}\left({\color{gray}2.92 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/book/v/1 $$35.0 \mathrm{ms} \pm 262 \mathrm{μs}\left({\color{gray}2.23 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/building/v/1 $$36.8 \mathrm{ms} \pm 338 \mathrm{μs}\left({\color{gray}2.52 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/organization/v/1 $$34.8 \mathrm{ms} \pm 312 \mathrm{μs}\left({\color{gray}-2.050 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/page/v/2 $$36.9 \mathrm{ms} \pm 300 \mathrm{μs}\left({\color{gray}2.69 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/person/v/1 $$34.5 \mathrm{ms} \pm 332 \mathrm{μs}\left({\color{gray}-2.947 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/playlist/v/1 $$35.4 \mathrm{ms} \pm 291 \mathrm{μs}\left({\color{gray}-1.917 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/song/v/1 $$37.2 \mathrm{ms} \pm 287 \mathrm{μs}\left({\color{red}5.30 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/uk-address/v/1 $$35.2 \mathrm{ms} \pm 299 \mathrm{μs}\left({\color{gray}2.03 \mathrm{\%}}\right) $$ Flame Graph

representative_read_entity_type

Function Value Mean Flame graphs
get_entity_type_by_id Account ID: bf5a9ef5-dc3b-43cf-a291-6210c0321eba $$8.67 \mathrm{ms} \pm 41.8 \mathrm{μs}\left({\color{gray}-1.015 \mathrm{\%}}\right) $$ Flame Graph

representative_read_multiple_entities

Function Value Mean Flame graphs
entity_by_property traversal_paths=0 0 $$94.7 \mathrm{ms} \pm 503 \mathrm{μs}\left({\color{gray}-1.604 \mathrm{\%}}\right) $$
entity_by_property traversal_paths=255 1,resolve_depths=inherit:1;values:255;properties:255;links:127;link_dests:126;type:true $$149 \mathrm{ms} \pm 964 \mathrm{μs}\left({\color{gray}-1.478 \mathrm{\%}}\right) $$
entity_by_property traversal_paths=2 1,resolve_depths=inherit:0;values:0;properties:0;links:0;link_dests:0;type:false $$101 \mathrm{ms} \pm 604 \mathrm{μs}\left({\color{gray}-1.090 \mathrm{\%}}\right) $$
entity_by_property traversal_paths=2 1,resolve_depths=inherit:0;values:0;properties:0;links:1;link_dests:0;type:true $$112 \mathrm{ms} \pm 766 \mathrm{μs}\left({\color{gray}-1.633 \mathrm{\%}}\right) $$
entity_by_property traversal_paths=2 1,resolve_depths=inherit:0;values:0;properties:2;links:1;link_dests:0;type:true $$119 \mathrm{ms} \pm 666 \mathrm{μs}\left({\color{gray}-1.622 \mathrm{\%}}\right) $$
entity_by_property traversal_paths=2 1,resolve_depths=inherit:0;values:2;properties:2;links:1;link_dests:0;type:true $$129 \mathrm{ms} \pm 760 \mathrm{μs}\left({\color{gray}-1.414 \mathrm{\%}}\right) $$
link_by_source_by_property traversal_paths=0 0 $$103 \mathrm{ms} \pm 588 \mathrm{μs}\left({\color{gray}-1.147 \mathrm{\%}}\right) $$
link_by_source_by_property traversal_paths=255 1,resolve_depths=inherit:1;values:255;properties:255;links:127;link_dests:126;type:true $$134 \mathrm{ms} \pm 771 \mathrm{μs}\left({\color{gray}-2.130 \mathrm{\%}}\right) $$
link_by_source_by_property traversal_paths=2 1,resolve_depths=inherit:0;values:0;properties:0;links:0;link_dests:0;type:false $$111 \mathrm{ms} \pm 572 \mathrm{μs}\left({\color{gray}-0.013 \mathrm{\%}}\right) $$
link_by_source_by_property traversal_paths=2 1,resolve_depths=inherit:0;values:0;properties:0;links:1;link_dests:0;type:true $$120 \mathrm{ms} \pm 641 \mathrm{μs}\left({\color{gray}-0.442 \mathrm{\%}}\right) $$
link_by_source_by_property traversal_paths=2 1,resolve_depths=inherit:0;values:0;properties:2;links:1;link_dests:0;type:true $$122 \mathrm{ms} \pm 687 \mathrm{μs}\left({\color{gray}-1.495 \mathrm{\%}}\right) $$
link_by_source_by_property traversal_paths=2 1,resolve_depths=inherit:0;values:2;properties:2;links:1;link_dests:0;type:true $$123 \mathrm{ms} \pm 655 \mathrm{μs}\left({\color{gray}-0.669 \mathrm{\%}}\right) $$

scenarios

Function Value Mean Flame graphs
full_test query-limited $$153 \mathrm{ms} \pm 2.23 \mathrm{ms}\left({\color{lightgreen}-16.984 \mathrm{\%}}\right) $$ Flame Graph
full_test query-unlimited $$150 \mathrm{ms} \pm 667 \mathrm{μs}\left({\color{lightgreen}-23.785 \mathrm{\%}}\right) $$ Flame Graph
linked_queries query-limited $$41.9 \mathrm{ms} \pm 239 \mathrm{μs}\left({\color{lightgreen}-61.350 \mathrm{\%}}\right) $$ Flame Graph
linked_queries query-unlimited $$565 \mathrm{ms} \pm 958 \mathrm{μs}\left({\color{lightgreen}-6.968 \mathrm{\%}}\right) $$ Flame Graph

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/libs Relates to first-party libraries/crates/packages (area) type/eng > backend Owned by the @backend team

Development

Successfully merging this pull request may close these issues.

1 participant