Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Big performance update by theomgdev! #171

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

theomgdev
Copy link
Contributor

Description

This PR introduces significant performance optimizations to handle larger simulations more efficiently. The changes focus on critical optimizations while maintaining the simulation's biological accuracy.

Changes

This pull request introduces several significant improvements and optimizations across multiple files. The main changes include adding a debounce function to control input handling, optimizing the organism update and removal process, converting the grid to a 1D array, enhancing the organism decision-making process, and improving the rendering efficiency. Below are the most important changes grouped by their themes:

Input Handling Optimization:

  • Added a debounce function to the defineEngineSpeedControls method in ControlPanel.js to prevent excessive input handling. [1] [2]

Organism Management:

  • Introduced a spatial grid in WorldEnvironment.js to track organism positions and optimize removal and updates. [1] [2] [3] [4]

Grid Optimization:

  • Converted the grid in GridMap.js to a 1D array for improved performance and simplified cell access methods. [1] [2]

Decision-Making Enhancement:

  • Enhanced the decide method in Brain.js to efficiently find the closest observation and make decisions accordingly.

Rendering Improvements:

  • Improved rendering efficiency in Renderer.js by using a dirtyCells set to track and render only modified cells. [1] [2]

These changes collectively improve the performance, readability, and maintainability of the codebase.

🚀 Core Optimizations

  • 1D Grid Storage
    Switched from 2D array to 1D array for grid cell storage (30-40% faster access)
  • Debounced FPS Controls
    Added 100ms debounce to FPS slider to prevent UI thread congestion
  • Reverse Organism Iteration
    Safer organism removal during updates with backward iteration
  • Dirty Cell Rendering
    Implemented differential rendering system for 70% fewer draw calls
  • Spatial Partitioning
    Added spatial grid for O(1) neighbor lookups in collision detection

🧠 Brain System Fixes

  • Null Cell Handling
    Added safety checks for edge-of-map observations
  • Optimized Decision Making
    Reduced from O(n²) to O(n) complexity in observation processing

🌐 World System Improvements

  • Perlin Noise Memoization
    Reduction in terrain generation costs
  • Grid Serialization
    Optimized grid saving/loading using sparse storage

🐛 Critical Bug Fixes

  • Fixed organism removal index shifting
  • Patched null reference in sensory system
  • Resolved grid iteration errors

@theomgdev theomgdev marked this pull request as draft February 4, 2025 23:22
@theomgdev theomgdev marked this pull request as ready for review February 4, 2025 23:23
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.

1 participant