Skip to content

Conversation

@Nimrais
Copy link
Member

@Nimrais Nimrais commented Dec 2, 2025

I had some time to read the rules for CT node. And I found a low-hanging fruit.

There are 3 places where we are computing:

for i in 1:dy
        xi += Fs[i]' * Vxymxy * mW[:, i]
        for j in 1:dy
            W += mW[j, i] * Fs[i]' * Vxmx * Fs[j]
        end
    end

But inner loop over dy can be moved on the upper level, and you will have linear complexity not quaratic over dy.

I made a small script until we are developing here to check the speed boost quickly benchmark/continuous_transition_bench.jl.

I think the code style could be slightly improved but I what do you think about it guys?

My branch:

(base) ➜  ReactiveMP.jl git:(optimize-double-loops-ct) ✗ julia --project=. benchmark/continuous_transition_bench.jl quick
  Activating project at `~/repos/optimize_ct/ReactiveMP.jl`
Precompiling ReactiveMP finished.
  1 dependency successfully precompiled in 18 seconds. 122 already precompiled.

================================================================================
  ContinuousTransition Rules Benchmark
  Branch: optimize-double-loops-ct
  Commit: 9d15c43c
================================================================================

  Mode: QUICK (limited dimensions)

------------------------------------------------------------
  Benchmarking: dx=10, dy=10 (da=100)
------------------------------------------------------------
    a.jl Structured:      240.50 μs
    a.jl Mean-field:      240.17 μs
    marginals.jl y_x:     302.17 μs

------------------------------------------------------------
  Benchmarking: dx=20, dy=20 (da=400)
------------------------------------------------------------
    a.jl Structured:     7034.29 μs
    a.jl Mean-field:     7414.62 μs
    marginals.jl y_x:    5671.83 μs

================================================================================
  SUMMARY TABLE (times in μs)
================================================================================

  Dimensions   |   a structured |    a meanfield |   marginal y x
  ------------ | -------------- | -------------- | --------------
    10 × 10    |         240.50 |         240.17 |         302.17
    20 × 20    |        7034.29 |        7414.62 |        5671.83

================================================================================
  Benchmark Complete
================================================================================

Main branch:

(base) ➜  ReactiveMP.jl git:(main) ✗ julia --project=. benchmark/continuous_transition_bench.jl quick
  Activating project at `~/repos/optimize_ct/ReactiveMP.jl`
Precompiling ReactiveMP finished.
  1 dependency successfully precompiled in 17 seconds. 122 already precompiled.

================================================================================
  ContinuousTransition Rules Benchmark
  Branch: main
  Commit: 8b3a7d0d
================================================================================

  Mode: QUICK (limited dimensions)

------------------------------------------------------------
  Benchmarking: dx=10, dy=10 (da=100)
------------------------------------------------------------
    a.jl Structured:     1222.42 μs
    a.jl Mean-field:     1168.00 μs
    marginals.jl y_x:    1005.62 μs

------------------------------------------------------------
  Benchmarking: dx=20, dy=20 (da=400)
------------------------------------------------------------
    a.jl Structured:   103807.00 μs
    a.jl Mean-field:    74746.12 μs
    marginals.jl y_x:   18672.21 μs

================================================================================
  SUMMARY TABLE (times in μs)
================================================================================

  Dimensions   |   a structured |    a meanfield |   marginal y x
  ------------ | -------------- | -------------- | --------------
    10 × 10    |        1222.42 |        1168.00 |        1005.62
    20 × 20    |      103807.00 |       74746.12 |       18672.21

================================================================================
  Benchmark Complete

@Nimrais Nimrais marked this pull request as draft December 2, 2025 14:04
@github-actions
Copy link
Contributor

github-actions bot commented Dec 2, 2025

🤖 Code Formatting

Your PR still has some code formatting issues. I've updated PR #572 with the necessary formatting changes.

You can merge that PR into this branch to fix the code style check.

Alternatively, you can run make format locally and push the changes yourself.

@Nimrais Nimrais requested a review from albertpod December 2, 2025 14:12
@codecov
Copy link

codecov bot commented Dec 2, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.29%. Comparing base (8b3a7d0) to head (6335b61).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #571   +/-   ##
=======================================
  Coverage   80.28%   80.29%           
=======================================
  Files         211      211           
  Lines        6265     6266    +1     
=======================================
+ Hits         5030     5031    +1     
  Misses       1235     1235           

☔ 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.

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