bevyengine / bevyengine/bevy

Consider shrinking ECS IDs

Open
#4,820 4 comments 1 reaction 0 assignees View on GitHub
A-ECS C-Feature C-Performance
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 16h
Merged PRs (30d)
171

Description

## What problem does this solve or what need does it fill?

Currently all of the ECS IDs (sans Entity) is backed with a `usize`, which might be bigger than it needs to be. It'll be difficult to find a use case that legitimately needs more than u32::MAX archetypes, tables, bundles or components, which means the upper 4 bytes on 64-bit machines effectively go unused.

For Components and Bundles, it may make sense to drop to u16, as most of these are determined at compile time, or are conservatively added via modding/scripting.

## What solution would you like?

Shrink ArchetypeId, TableId, ArchetypeComponentId to u32.

Tentatively shrink ComponentId and BundleId to u16.

## What alternative(s) have you considered?

Leaving them as is.

## Additional context

As a good portion of the metadata storage for ECS is stored in SparseSets embedded in Archetypes and Tables, shrinking these IDs can shrink the size of these sets, keeping them hotter in caches, and thus reducing access overhead.

Contributor guide

Open the contributing guide

Research direction

Start by locating the definitions and uses of ArchetypeId, TableId, ArchetypeComponentId, ComponentId, and BundleId, then trace the SparseSets embedded in Archetypes and Tables. Check how each ID is stored and propagated before deciding whether the proposed u32 and u16 widths are safe. Done means the IDs use the intended smaller widths and the affected ECS metadata remains consistent.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
game-dev, performance
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.