Skip to main content

ExtractContextCache

Struct ExtractContextCache 

Source
pub struct ExtractContextCache { /* private fields */ }
Expand description

Per-extract-phase memo of the parent-derived maps that every extract fn recomputes identically within a single frame.

The default extract pass runs six extract fns back-to-back (extract_shadows, extract_rects, extract_borders, extract_text, extract_clips, extract_scrollbars) - plus the image/SVG extractors registered by lumen-assets - and each one independently rebuilds the same hierarchy-derived structures via build_parent_map, hidden_entities, parent_scroll_offsets, parent_opacities, and parent_scroll_clip_rects. Those depend only on the main-world hierarchy / ScrollOffset / Opacity / Visible / clip components, none of which mutate between extractors of the same phase (extract fns only read the main world and write the render world). Recomputing them six times is pure redundant traversal + allocation on every dirty frame - the steady-state cost of any animation, scroll, or state change.

crate::app::App::tick wraps the extract-fn loop with Self::begin_phase / Self::end_phase. The first extractor of a phase computes each map and stores a copy here; the rest clone it back (an O(n) memcpy instead of the query + DFS + sort rebuild). Reuse is gated on Self::active, so Systems-stage callers that share these helpers - hit-testing hover, which runs before the <if> / <for> reconcilers have finalised the tree - never observe a cached, stale hierarchy: with active == false they always recompute. begin_phase clears every slot, so no data survives across phases either.

Mirrors the “compute the frame’s scene-graph context once” pattern in retained-scene toolkits (Qt Quick’s QSGRenderContext, GTK4’s snapshot pass): shared per-frame derivations are built once and threaded through the emitters, not rederived per draw-list.

Implementations§

Source§

impl ExtractContextCache

Source

pub fn begin_phase(&mut self)

Open the extract phase: enable reuse and drop any slots left from a prior phase so the first extractor recomputes against the current (post-reconcile, post-layout) hierarchy.

Source

pub fn end_phase(&mut self)

Close the extract phase: disable reuse and release the memoised maps so they cannot be observed by out-of-phase callers or pin memory between frames.

Trait Implementations§

Source§

impl Component for ExtractContextCache
where Self: Send + Sync + 'static,

Source§

const STORAGE_TYPE: StorageType = bevy_ecs::component::StorageType::SparseSet

A constant indicating the storage type used for this component.
Source§

type Mutability = Mutable

A marker type to assist Bevy with determining if this component is mutable, or immutable. Mutable components will have Component<Mutability = Mutable>, while immutable components will instead have Component<Mutability = Immutable>. Read more
Source§

fn register_required_components( _requiree: ComponentId, required_components: &mut RequiredComponentsRegistrator<'_, '_>, )

Registers required components. Read more
Source§

fn clone_behavior() -> ComponentCloneBehavior

Called when registering this component, allowing to override clone function (or disable cloning altogether) for this component. Read more
Source§

fn relationship_accessor() -> Option<ComponentRelationshipAccessor<Self>>

Returns [ComponentRelationshipAccessor] required for working with relationships in dynamic contexts. Read more
§

fn on_add() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>

Gets the on_add [ComponentHook] for this Component if one is defined.
§

fn on_insert() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>

Gets the on_insert [ComponentHook] for this Component if one is defined.
§

fn on_discard() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>

Gets the on_discard [ComponentHook] for this Component if one is defined.
§

fn on_remove() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>

Gets the on_remove [ComponentHook] for this Component if one is defined.
§

fn on_despawn() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>

Gets the on_despawn [ComponentHook] for this Component if one is defined.
§

fn map_entities<E>(_this: &mut Self, _mapper: &mut E)
where E: EntityMapper,

Maps the entities on this component using the given EntityMapper. This is used to remap entities in contexts like scenes and entity cloning. When deriving Component, this is populated by annotating fields containing entities with #[entities] Read more
Source§

impl Default for ExtractContextCache

Source§

fn default() -> ExtractContextCache

Returns the “default value” for a type. Read more
Source§

impl Resource for ExtractContextCache
where Self: Send + Sync + 'static,

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<C> Bundle for C
where C: Component,

§

fn component_ids( components: &mut ComponentsRegistrator<'_>, ) -> impl Iterator<Item = ComponentId> + use<C>

§

fn get_component_ids( components: &Components, ) -> impl Iterator<Item = Option<ComponentId>>

Return a iterator over this Bundle’s component ids. This will be None if the component has not been registered.
§

impl<C> BundleFromComponents for C
where C: Component,

§

unsafe fn from_components<T, F>(ctx: &mut T, func: &mut F) -> C
where F: for<'a> FnMut(&'a mut T) -> OwningPtr<'a>,

§

impl<C> DynamicBundle for C
where C: Component,

§

type Effect = ()

An operation on the entity that happens after inserting this bundle.
§

unsafe fn get_components( ptr: MovingPtr<'_, C>, func: &mut impl FnMut(StorageType, OwningPtr<'_>), ) -> <C as DynamicBundle>::Effect

Moves the components out of the bundle. Read more
§

unsafe fn apply_effect( _ptr: MovingPtr<'_, MaybeUninit<C>>, _entity: &mut EntityWorldMut<'_>, )

Applies the after-effects of spawning this bundle. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromWorld for T
where T: Default,

§

fn from_world(_world: &mut World) -> T

Creates Self using default().

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> IntoResult<T> for T

§

fn into_result(self) -> Result<T, RunSystemError>

Converts this type into the system output type.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> ConditionalSend for T
where T: Send,