Skip to content

algo.influenceMaximization allocates two nodeCount-sized arrays per Monte Carlo simulation #6265

Closed

Description

@lvca

Split out of #6216 / PR #6222, where it was noticed twice while reasoning about checkpoint placement and deliberately left alone: it is a performance defect, not a validation one, and folding it into a bounds-checking fix would have made that PR harder to review.

The allocation

AlgoInfluenceMaximization.simulateIC opens with two fresh arrays on every call:

private int simulateIC(final int[][] adj, final int[] seeds, final int seedCount,
    final int candidate, final int n, final double p, final Random rng) {
  final boolean[] activated = new boolean[n];
  // BFS queue (int[] with head/tail pointers — zero boxing)
  final int[] queue = new int[n];

The comment above the queue is telling: the method was written to avoid boxing in the inner loop, and then allocates 5n bytes per call anyway.

How often that is

simulateIC sits at the bottom of a triple nest - round x candidate x sim:

for (int round = 0; round < seedCount; round++)
  for (int candidate = 0; candidate < n; candidate++)
    for (int sim = 0; sim < simulations; sim++)
      totalSpread += simulateIC(...);

So the call count is k x n x simulations, and each call allocates and zero-fills n booleans plus n ints. Total churn is k x n^2 x simulations x 5 bytes.

At the default simulations: 100 with k = 3:

nodes calls bytes allocated and zeroed
1 000 300 000 ~1.5 GB
10 000 3 000 000 ~150 GB
100 000 30 000 000 ~15 TB

None of it survives the call, so it is pure allocation-rate and zero-fill cost on top of an algorithm that is already O(k x n x simulations x (n + m)).

Fix

Hoist both buffers to the caller and clear them per simulation. The clear can be cheaper than the allocation in the common case: an IC cascade usually activates far fewer than n nodes, so resetting only the entries recorded in queue[0..tail) is O(activated) rather than O(n), where the current code pays O(n) twice per call regardless.

That turns the per-simulation cost from 2 x O(n) allocate-and-zero into O(activated), which on a sparse graph with a low propagationProbability is a large constant-factor win - exactly the regime the defaults describe.

Note on the checkpoint

AlgoInfluenceMaximization's simulation loop calls the unthrottled guard.check() rather than checkPeriodically, and the comment at that call site justifies it by saying simulateIC "allocates and zero-fills two arrays of size n before the cascade starts, so it is never O(1) on any graph shape". That reasoning is load-bearing on the very allocation this issue removes.

If the buffers are hoisted, a simulation on a small graph can become close to O(1), and the checkpoint should be re-examined in the same change - most likely by keeping check() (its cost is one flag test when no timeout is configured) but updating the comment, since the alternative of throttling to 1024 makes abort latency 1024 x O(n + m) on large graphs. Either way the comment must not be left asserting something that is no longer true.

Related

#6216, PR #6222.

Activity

  1. self-assigned this
    on Aug 16, 2026
  2. added this to the 26.9.1 milestone on Aug 16, 2026
  3. added
    in progress
    on Aug 24, 2026
  4. added a commit that references this issue on Aug 25, 2026
  5. removed
    in progress
    on Aug 25, 2026
  6. lvca commented on Aug 25, 2026

    @lvca
    MemberAuthor

    Fixed in #6714. `algo.influenceMaximization` used to allocate fresh memory on every single simulation it runs internally, which added up fast on large graphs. It now reuses the same memory across all simulations, so it needs a lot less RAM and runs faster. Results are unchanged.


    ❤️ Thanks for helping make ArcadeDB better! ArcadeDB is free and open source, sustained by its community. If it's useful to you or your company, please consider becoming a sponsor to keep development going.

  7. added a commit that references this issue on Aug 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions