-
Notifications
You must be signed in to change notification settings - Fork 2
Support configurable multi-threaded parallel execution in ECS systems and RenderContentBaseSystem with comprehensive thread safety #278
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
base: main
Are you sure you want to change the base?
Conversation
…ems and RenderContentBaseSystem Co-authored-by: yorkie <1935767+yorkie@users.noreply.github.com>
…ature Co-authored-by: yorkie <1935767+yorkie@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot You need to make sure the thread-safty, please check related source files again.
- Make WebContent dirty state atomic (is_content_dirty_, is_surface_dirty_) - Add ComponentSet mutex protection for all data structure access - Update ComponentSet methods to use shared_mutex for thread safety - Add thread safety documentation to parallel execution methods - Enhance parallel execution documentation with safety details - Add comprehensive test for thread-safe component access - Ensure proper synchronization in parallel systems and rendering Co-authored-by: yorkie <1935767+yorkie@users.noreply.github.com>
I've addressed the thread safety concerns with comprehensive improvements in commit ab3c963: Key Thread Safety Fixes:
Thread Safety Mechanisms:
Testing: Added comprehensive thread safety tests that verify concurrent component access works correctly in parallel systems. The implementation now ensures that multiple systems can safely access components concurrently without data races or inconsistent state. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
This PR implements configurable multi-threaded parallel execution for ECS systems and WebContent rendering to improve performance in complex spatial applications with many dynamic elements, with comprehensive thread safety mechanisms to ensure safe concurrent access.
Overview
The implementation adds opt-in parallelization support that can significantly improve performance on multi-core systems while maintaining full backwards compatibility. By default, all execution remains sequential to preserve existing behavior.
Key Features
Configuration Options
JSAR_PARALLEL_SYSTEMS=1
andJSAR_PARALLEL_RENDER=true
setParallelSystemsEnabled(true)
andsetParallelRenderEnabled(true)
isParallelSystemsEnabled()
andisParallelRenderEnabled()
ECS Systems Parallelization
Systems within the same scheduler label can now run concurrently:
The implementation uses
std::async
with proper synchronization viastd::future::wait()
to ensure thread safety.WebContent Rendering Parallelization
Multiple
WebContent
entities can now render concurrently inRenderContentBaseSystem::onExecute()
, reducing frame times for scenes with many spatial web contents.Performance Impact
Expected performance improvements based on workload characteristics:
Single systems or GPU-bound workloads see no performance change, ensuring no overhead when parallelization doesn't benefit the use case.
Thread Safety
The implementation maintains comprehensive thread safety through:
ComponentSet
has its ownshared_mutex
protecting component data accessstd::atomic<bool>
for concurrent accessmutexForEntities_
protects entity lifecycle operationsmutexForSystems_
protects system registration and removalstd::future::wait()
to ensure all parallel tasks completeComponent Access Safety
Testing & Documentation
docs/parallel-execution.md
covering usage, performance considerations, and troubleshootingexamples/parallel_execution_example.cpp
demonstrating performance differencesBackwards Compatibility
Fixes #277.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.