Skip to content

Speed up synthetic generator hot paths by removing avoidable quadratic and allocation-heavy work#1304

Merged
SkBlaz merged 3 commits intomasterfrom
copilot/speed-up-synthetic-generators
Mar 28, 2026
Merged

Speed up synthetic generator hot paths by removing avoidable quadratic and allocation-heavy work#1304
SkBlaz merged 3 commits intomasterfrom
copilot/speed-up-synthetic-generators

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 28, 2026

Synthetic generators had avoidable overhead in core sampling loops, especially in social/work edge generation and multiplex mapping accumulation. This PR makes targeted internal optimizations to reduce generator runtime without changing public APIs or output semantics.

  • Work-layer generation: eliminate cross-department pair checks

    • In make_social_network(), replaced global O(n^2) pair scanning with department-local pairing.
    • Effect: only evaluates candidate pairs that can actually produce work edges.
  • Multiplex generator: remove repeated list reallocations

    • In random_multiplex_generator(), replaced dict.get(...)+[x] list concatenation with in-place append via setdefault(...).append(...).
    • Effect: avoids per-iteration list copying in two accumulation paths (layer_to_nodes, edge_to_layers).
  • Minor cleanup

    • Removed an unnecessary cast in the department grouping path and a small typing/literal cleanup in random_generators.py.

Example of the core optimization pattern:

# before
layer_to_nodes[l] = layer_to_nodes.get(l, []) + [node]

# after
layer_to_nodes.setdefault(l, []).append(node)

@SkBlaz SkBlaz marked this pull request as ready for review March 28, 2026 09:32
@SkBlaz SkBlaz self-requested a review as a code owner March 28, 2026 09:32
@SkBlaz SkBlaz merged commit 6231696 into master Mar 28, 2026
33 checks passed
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