Skip to content

New API for supporting mut aliasing safety#1753

Open
Indra-db wants to merge 49 commits into
SanderMertens:masterfrom
Indra-db:table_column_locks_cr_locks
Open

New API for supporting mut aliasing safety#1753
Indra-db wants to merge 49 commits into
SanderMertens:masterfrom
Indra-db:table_column_locks_cr_locks

Conversation

@Indra-db
Copy link
Copy Markdown
Contributor

@Indra-db Indra-db commented Aug 17, 2025

This PR introduces:

  • locking for either component records (sparse components) or table-column locks (non-sparse components).
  • separate per-thread / per-stage locking for table columns.
  • everything gated by the FLECS_MUT_ALIAS_LOCKS define, so there is no performance impact when it’s not enabled.
  • build tests and unit tests for the behaviour.

End users of this internal API must use it themselves and panic when the mut-alias guarantee is violated.

ecs_lock_target_t holds information about where the lock should be applied. For sparse components/IDs (sparse and/or non-fragmenting) it will use the component_record for locking. For table-column components it will lock the individual column.

@Indra-db
Copy link
Copy Markdown
Contributor Author

ci test, I expect a failure somewhere, I cannot run tests locally due to bake being problematic (see discord)

@Indra-db
Copy link
Copy Markdown
Contributor Author

all tests passing 🥳

@Reddy-dev
Copy link
Copy Markdown
Contributor

Reddy-dev commented Aug 21, 2025

ci test, I expect a failure somewhere, I cannot run tests locally due to bake being problematic (see discord)

@Indra-db could you link the message, I think i also have similar issues

@Indra-db
Copy link
Copy Markdown
Contributor Author

@Reddy-dev

Tldr, Sander told me to use bake run as opposed to bake test which should fix the ouput

@Indra-db
Copy link
Copy Markdown
Contributor Author

@Reddy-dev this was my thread where I was dumping my experience (which I closed)
https://discord.com/channels/633826290415435777/1406452408149741770/1406998533449580585

@Indra-db
Copy link
Copy Markdown
Contributor Author

update to latest main

Comment thread include/flecs/private/api_internals.h Outdated
Comment thread include/flecs/private/api_internals.h Outdated
Comment thread include/flecs/private/api_internals.h Outdated
@Indra-db Indra-db changed the title table column & component record safety locks table column & component record mut alias locks Sep 23, 2025
@Indra-db Indra-db changed the title table column & component record mut alias locks table column & component record mut alias locks internal API Sep 23, 2025
@SanderMertens SanderMertens changed the title table column & component record mut alias locks internal API New API for supporting mut aliasing safety Sep 23, 2025
@Indra-db Indra-db force-pushed the table_column_locks_cr_locks branch from 03f2a1c to 3e9b117 Compare October 12, 2025 17:21
@Indra-db Indra-db force-pushed the table_column_locks_cr_locks branch from d4af765 to 82365c3 Compare November 17, 2025 02:30
@SanderMertens
Copy link
Copy Markdown
Owner

I'm still seeing performance regressions when comparing with latest master:

Screenshot 2025-12-06 at 2 44 11 PM

I think it's better to separate out the implementation into its own functions so there's no risk of regressions.

(Note: benchmarks were done without the FLECS_MUT_ALIAS_LOCKS flag on a regular Flecs master)

@Indra-db Indra-db force-pushed the table_column_locks_cr_locks branch from 8f5ff7d to cc8a6da Compare December 24, 2025 02:21
@Indra-db Indra-db force-pushed the table_column_locks_cr_locks branch from 2b83d41 to a02bb75 Compare May 10, 2026 10:29
@github-project-automation github-project-automation Bot moved this to Backlog in Flecs 4.2 May 20, 2026
@SanderMertens SanderMertens moved this from Backlog to Ready in Flecs 4.2 May 20, 2026
Comment thread include/flecs/private/api_internals.h Outdated
Comment thread include/flecs/private/api_internals.h Outdated
Comment thread include/flecs/private/api_internals.h Outdated
Comment thread src/storage/component_index.c Outdated
Comment thread src/storage/table.c Outdated
Comment thread src/storage/table.c Outdated
Comment thread src/entity.c Outdated
@Indra-db Indra-db requested a review from SanderMertens May 27, 2026 03:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Ready

Development

Successfully merging this pull request may close these issues.

3 participants