turbo-tasks-backend: reuse the task ids freed by GC, after a deferral window
The motivation is density, not exhaustion: the persistent id space is ~1.07B and real sessions stay under 15M, but keeping the live id set packed near [1, max_live) is what makes flat, array-backed storage viable in place of a sharded DashMap. The metric is peak minted id vs. peak live task count. Ids are not handed back the moment they are freed. A stale reference that outlived its task currently fails loudly — open_task with MustExist asserts the task "exists in neither memory nor persistent storage" — and immediate reuse would turn that panic into a silently wrong answer against an unrelated live task. While an id waits in the deferral queue it is in neither the resident map, the task cache, nor on disk, so that assert still fires. The window preserves the existing loud failure rather than merely making aliasing unlikely. The window is counted in snapshot cycles because the hazard is phase-relative, not volume-relative; a quiet session simply doesn't reuse. Ids enter the queue from evict_after_snapshot only after the deferred task_cache drain, since an id whose task_cache entry survives could still be handed back by get_or_create_persistent_task. Configurable via BackendOptions::id_reuse_delay_cycles or TURBO_ENGINE_ID_REUSE_DELAY_CYCLES; 0 releases on the next cycle, which is the maximum-aliasing-pressure setting for tests. Generation-tagged ids were considered as a stronger alternative and rejected: they give every task a masked in-memory identity and an unmasked on-disk key, and kv_backing_storage converts ids to key bytes by bare deref in several places, so a missed mask is a silent wrong-row read. The reasoning is recorded in the id_reuse module docs.
Showing
Please
register
or
sign in
to comment