Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ categories = ["gui"]
license = "MIT"

[dependencies]
## Enable use of stacksafe in recursive callsites, preventing stack overflows at the cost of performance penalties
stacksafe = { version = "0.1", default-features = false, optional = true }
arrayvec = { version = "0.7", default-features = false }
document-features = { version = "0.2.7", optional = true }
serde = { version = "1.0", default-features = false, optional = true, features = ["serde_derive"] }
Expand Down
3 changes: 3 additions & 0 deletions src/compute/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ struct BlockItem {
}

/// Computes the layout of [`LayoutPartialTree`] according to the block layout algorithm
#[cfg_attr(feature = "stacksafe", stacksafe::stacksafe)]
pub fn compute_block_layout(
tree: &mut impl LayoutBlockContainer,
node_id: NodeId,
Expand Down Expand Up @@ -122,6 +123,7 @@ pub fn compute_block_layout(
}

/// Computes the layout of [`LayoutBlockContainer`] according to the block layout algorithm
#[cfg_attr(feature = "stacksafe", stacksafe::stacksafe)]
Copy link
Collaborator

Choose a reason for hiding this comment

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

I expect this and perform_final_layout_on_in_flow_children aren't necessary, but are probably harmless.

fn compute_inner(tree: &mut impl LayoutBlockContainer, node_id: NodeId, inputs: LayoutInput) -> LayoutOutput {
let LayoutInput {
known_dimensions, parent_size, available_space, run_mode, vertical_margins_are_collapsible, ..
Expand Down Expand Up @@ -390,6 +392,7 @@ fn determine_content_based_container_width(

/// Compute each child's final size and position
#[inline]
#[cfg_attr(feature = "stacksafe", stacksafe::stacksafe)]
fn perform_final_layout_on_in_flow_children(
tree: &mut impl LayoutPartialTree,
items: &mut [BlockItem],
Expand Down
1 change: 1 addition & 0 deletions src/compute/flexbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ struct AlgoConstants {
}

/// Computes the layout of a box according to the flexbox algorithm
#[cfg_attr(feature = "stacksafe", stacksafe::stacksafe)]
pub fn compute_flexbox_layout(
tree: &mut impl LayoutFlexboxContainer,
node: NodeId,
Expand Down
1 change: 1 addition & 0 deletions src/compute/grid/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ mod util;
/// - Placing items (which also resolves the implicit grid)
/// - Track (row/column) sizing
/// - Alignment & Final item placement
#[cfg_attr(feature = "stacksafe", stacksafe::stacksafe)]
pub fn compute_grid_layout<Tree: LayoutGridContainer>(
tree: &mut Tree,
node: NodeId,
Expand Down
2 changes: 2 additions & 0 deletions src/compute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ pub fn compute_root_layout(tree: &mut impl LayoutPartialTree, root: NodeId, avai
/// Attempts to find a cached layout for the specified node and layout inputs.
///
/// Uses the provided closure to compute the layout (and then stores the result in the cache) if no cached layout is found.
#[cfg_attr(feature = "stacksafe", stacksafe::stacksafe)]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Removing from here might help perf, because this function gets called just prior to Taffy reading from it's cache. It's also probably not necessary here, because:

  • If there's a cache hit then we will immediately return back up the stack
  • If there's a cache miss then we will recurse into another function which will be annotated

#[inline(always)]
pub fn compute_cached_layout<Tree: CacheTree + ?Sized, ComputeFunction>(
tree: &mut Tree,
Expand Down Expand Up @@ -208,6 +209,7 @@ pub fn round_layout(tree: &mut impl RoundTree, node_id: NodeId) {
return round_layout_inner(tree, node_id, 0.0, 0.0);

/// Recursive function to apply rounding to all descendents
#[cfg_attr(feature = "stacksafe", stacksafe::stacksafe)]
fn round_layout_inner(tree: &mut impl RoundTree, node_id: NodeId, cumulative_x: f32, cumulative_y: f32) {
let unrounded_layout = tree.get_unrounded_layout(node_id);
let mut layout = unrounded_layout;
Expand Down
1 change: 1 addition & 0 deletions src/tree/taffy_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ where
}

#[inline(always)]
#[cfg_attr(feature = "stacksafe", stacksafe::stacksafe)]
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd also remove here for same reason as above. This is just prior to hitting the cache, and we'd like to only run this check if we get a cache miss to keep cache access fast.

fn compute_child_layout(&mut self, node: NodeId, inputs: LayoutInput) -> LayoutOutput {
// If RunMode is PerformHiddenLayout then this indicates that an ancestor node is `Display::None`
// and thus that we should lay out this node using hidden layout regardless of it's own display style.
Expand Down