Skip to content

Refactor _add_agent in ContinuousSpace - #3556

Merged
quaquel merged 1 commit into
mesa:mainfrom
codebreaker32:refactor/_add_agent
Mar 16, 2026
Merged

quaquel merged 1 commit into
mesa:mainfrom
codebreaker32:refactor/_add_agent

Conversation

@codebreaker32

@codebreaker32 codebreaker32 commented Mar 16, 2026 •

Copy link
Copy Markdown
Collaborator

Important

For enhancements and new features, include the issue/discussion where a maintainer approved this work before opening a PR. Unapproved feature/enhancement PRs may be closed.

Pre-PR Checklist

  • I linked an issue/discussion where a maintainer approved this enhancement/feature for implementation.

Approval Link

#3548

Summary

This PR optimizes the memory reallocation strategy inside ContinuousSpace._add_agent by replacing the existing np.vstack call with a faster array pre-allocation and slice assignment approach.

Motive

See #3548

Implementation

Replaced np.vstack with a pre-allocation strategy and slice assignment

Usage Examples

It remains same as this is an internal refactor

Additional Notes

Closes #3548


GSoC contributor checklist

Context & motivation

This is my prerequisite effort to make continuous space and continuous space agent faster or optimise wherever there is scope before we start working on stacked spaces.

What I learned

See #2585 and #3458 for background

Learning repo

🔗 My learning repo: https://github.com/codebreaker32/GSoC-learning-space
🔗 Relevant model(s): NA

Readiness checks

  • This PR addresses an agreed-upon problem (linked issue or discussion with maintainer approval), or is a small/trivial fix
  • I have read the contributing guide and deprecation policy
  • I have performed a self-review: I reviewed my own PR as if I were a reviewer and left comments on anything that needs explanation
  • Another GSoC contributor has reviewed this PR: @
  • Tests pass locally (pytest --cov=mesa tests/)
  • Code is formatted (ruff check . --fix)
  • If applicable: documentation, examples, and/or migration guide are updated

@github-actions

Copy link
Copy Markdown

Performance benchmarks:

Model Size Init time [95% CI] Run time [95% CI]
BoltzmannWealth small 🔵 -1.5% [-2.0%, -1.0%] 🔵 -2.6% [-3.0%, -2.2%]
BoltzmannWealth large 🔵 -0.7% [-1.8%, +0.5%] 🔵 +0.9% [-2.7%, +3.9%]
Schelling small 🔵 -0.6% [-1.3%, +0.0%] 🔵 -0.2% [-1.3%, +0.7%]
Schelling large 🔵 -0.6% [-1.1%, -0.1%] 🟢 -4.9% [-6.2%, -3.5%]
WolfSheep small 🔵 -1.8% [-2.3%, -1.3%] 🔵 -4.0% [-8.1%, -0.0%]
WolfSheep large 🔵 +4.3% [+2.7%, +6.1%] 🔴 +7.9% [+5.1%, +10.4%]
SugarscapeG1mt small 🔵 +2.5% [+1.8%, +3.3%] 🔵 +0.7% [-0.8%, +2.3%]
SugarscapeG1mt large 🔵 -0.0% [-2.5%, +3.1%] 🔵 +0.5% [-0.7%, +1.6%]
BoidFlockers small 🔵 -0.6% [-1.3%, +0.1%] 🔵 +0.5% [+0.1%, +1.0%]
BoidFlockers large 🔵 -1.3% [-1.8%, -0.9%] 🔵 +0.1% [-0.2%, +0.3%]

@quaquel
quaquel merged commit 1dbdb37 into mesa:main Mar 16, 2026
12 checks passed
@quaquel quaquel added the performance Release notes label label Mar 16, 2026
@codebreaker32
codebreaker32 deleted the refactor/_add_agent branch March 16, 2026 17:34
PietroMondini pushed a commit to PietroMondini/mesa that referenced this pull request Mar 19, 2026
codebreaker32 added a commit to codebreaker32/mesa that referenced this pull request Apr 1, 2026
EwoutH pushed a commit that referenced this pull request Oct 28, 2026
@EwoutH EwoutH mentioned this pull request Nov 15, 2026
53 of 65 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Release notes label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace np.vstack in ContinuousSpace by array growth approach inspired from NumpyAgentDataset

2 participants