Skip to content

Avoid string lookups in cell interaction hot paths - #440

Open
whahnsr wants to merge 1 commit into
MathCancer:developmentfrom
whahnsr:optimize-cell-type-lookups
Open

whahnsr wants to merge 1 commit into
MathCancer:developmentfrom
whahnsr:optimize-cell-type-lookups

Conversation

@whahnsr

@whahnsr whahnsr commented Oct 22, 2026

Copy link
Copy Markdown

Summary

Replace repeated string-based cell-type lookups with integer-indexed
accesses in:

  • standard_cell_cell_interactions()
  • dynamic_spring_attachments()

The changes use the existing cell_definition_indices_by_type registry
and directly access the corresponding parameter vectors.

No floating-point arithmetic is changed.

Performance

Measured with perf stat -r 5 -e cycles:u on the heterogeneity example.

Single OpenMP thread, GCC -O3 -march=native.

Metric Original Optimized Improvement
CPU cycles 7,032,464,992 6,105,614,351 13.18% fewer
Elapsed time 1.9178 s 1.6679 s 13.03% less

Numerical validation

Both original and optimized versions produced byte-for-byte identical:

  • final_cells.mat
  • final_microenvironment0.mat

Verified in two examples:

  1. heterogeneity
  2. celltypes3 (75 initial cells across three types)

The celltypes3 simulation contained 130 neighbor links,
including 90 links between different cell types.

All comparisons passed.

Use integer cell-type indices for interaction rates, immunogenicity, and spring attachment affinity.

The heterogeneity benchmark shows 13.18% fewer CPU cycles and 13.03% lower elapsed time across five runs.

Numerical outputs are bit-identical to baseline in both heterogeneity and celltypes3 examples.

Co-authored-by: ChatGPT <chatgpt@openai.com>

@drbergman drbergman left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks like a clean set of changes with a modest performance gain. In my own ad hoc testing, I saw a ~5% speedup on heterogeneity (edits: max time = 90min, #threads = 1).

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