Skip to content

Conversation

@zakarumych
Copy link

Objective

  • Use strongly typed ticks with 64 bit integer value within.
  • Avoid tick counter overflow
  • Continue using 32 bit tick id in components. Keep existing system that prevents component age to overflow 32 bit.

Changelog

  • Tick values are now strongly typed as Tick and SmallTick.
  • Tick now contains NonZeroU64 and never overflow in any reasonable time.
  • SmallTick are used to store tick index when component addition and last modification. It contains u32 with lower 32 bits of Ticks 64 bit value.
  • World now uses TickCounter that implements tick incrementing and necessary bookkeeping.

Migration Guide

  • Custom System implementations have to switch to strongly typed Tick values and remove few methods.

Pick one

This is alternative to #6327 where components get their ticks grown to 64 bit as well.
And #6327 doesn't introduce strongly typed ticks. Can be implemented though.

@alice-i-cecile alice-i-cecile added A-ECS Entities, components, systems, and events C-Performance A change motivated by improving speed, memory usage or compile times C-Usability A targeted quality-of-life change that makes Bevy easier to use labels Nov 17, 2022
Copy link
Member

@james7132 james7132 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only a cursory scan. Have not done a full review of the updated logic just yet.

You do not need #[inline(always)] for most of these functions at this size. They're almost always guaranteed to inline even in debug mode.

Again, like #6327, this needs benchmarking to show the changes in performance here. This also has sizable overlap with #6547, which does something similar on the storage side. There's inevitably going to be merge conflicts between the two.

system_meta: &SystemMeta,
world: &'w World,
change_tick: u32,
change_tick: Tick,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
change_tick: Tick,
change_tick: #path::change_detection::Tick,

/// than `SMALL_TICK_AGE_THRESHOLD` may return false positive.
/// Which is acceptable tradeoff given that too old targets should
/// not occur outside some edge cases.
///
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
///

}

impl Tick {
#[inline(always)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#[inline(always)]

pub struct Tick(pub NonZeroU64);

impl Display for Tick {
#[inline(always)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#[inline(always)]

}

impl SmallTick {
#[inline(always)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#[inline(always)]

/// not occur outside some edge cases.
///
#[repr(transparent)]
#[derive(Clone, Copy, Debug)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, Default)]

Comment on lines +91 to +96
impl Default for SmallTick {
#[inline(always)]
fn default() -> Self {
SmallTick::new()
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
impl Default for SmallTick {
#[inline(always)]
fn default() -> Self {
SmallTick::new()
}
}

Comment on lines +56 to +61
impl Default for Tick {
#[inline(always)]
fn default() -> Self {
Tick::new()
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
impl Default for Tick {
#[inline(always)]
fn default() -> Self {
Tick::new()
}
}

}
}

// #[allow(clippy::useless_conversion)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// #[allow(clippy::useless_conversion)]

Comment on lines +258 to +264
// Safety:
// `TICK_BASE_VALUE` is nonzero
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Safety:
// `TICK_BASE_VALUE` is nonzero
// SAFETY: `TICK_BASE_VALUE` is nonzero

@james7132 james7132 added the S-Needs-Benchmarking This set of changes needs performance benchmarking to double-check that they help label Nov 20, 2022
@james7132
Copy link
Member

#6547 has been merged. Can you rebase? I'll run a set of microbenchmarks for comparison.

@ItsDoot ItsDoot added the S-Adopt-Me The original PR author has no intent to complete this work. Pick me up! label Aug 19, 2024
@bas-ie
Copy link
Contributor

bas-ie commented Oct 6, 2024

Backlog cleanup: closing this and alternate approach #6327 due to inactivity and no clear consensus.

@bas-ie bas-ie closed this Oct 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ECS Entities, components, systems, and events C-Performance A change motivated by improving speed, memory usage or compile times C-Usability A targeted quality-of-life change that makes Bevy easier to use S-Adopt-Me The original PR author has no intent to complete this work. Pick me up! S-Needs-Benchmarking This set of changes needs performance benchmarking to double-check that they help

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants