Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Handle reordedering of keyed children #1015

Merged
merged 8 commits into from
Dec 19, 2024

Conversation

marc2332
Copy link
Owner

@marc2332 marc2332 commented Dec 18, 2024

These two code blocksd didn't work correctly before:

#![cfg_attr(
    all(not(debug_assertions), target_os = "windows"),
    windows_subsystem = "windows"
)]

use freya::prelude::*;
use rand::Rng;

fn main() {
    launch_with_props(app, "Counter", (400.0, 350.0));
}

fn app() -> Element {
    let mut data = use_signal(Vec::<usize>::new);

    rsx!(
        rect {
            height: "100%",
            width: "100%",
            Button {
                onclick: move |_| {
                    let mut item = data.write().remove(0);
                    data.write().push(item);
                },
                label {
                    "Move"
                }
            }
            Button {
                onclick: move |_| {
                    let mut rng = rand::thread_rng();
                    data.write().insert(0,rng.gen());
                },
                label {
                    "Add"
                }
            }
            for d in data.read().iter() {
                label {
                    key: "{d}",
                    height: "20",
                    "{d}"
                }
            }
        }
    )
}
#![cfg_attr(
    all(not(debug_assertions), target_os = "windows"),
    windows_subsystem = "windows"
)]

use freya::prelude::*;
use rand::Rng;

fn main() {
    launch_with_props(app, "Counter", (400.0, 350.0));
}

fn app() -> Element {
    let mut data = use_signal(Vec::<usize>::new);

    rsx!(
        rect {
            height: "100%",
            width: "100%",
            Button {
                onclick: move |_| {
                    let l = data.len() - 1;
                    let mut item = data.write().remove(l);
                    data.write().insert(0, item);
                },
                label {
                    "Move"
                }
            }
            Button {
                onclick: move |_| {
                    let mut rng = rand::thread_rng();
                    data.write().push(rng.gen());
                },
                label {
                    "Add"
                }
            }
            for d in data.read().iter() {
                label {
                    key: "{d}",
                    height: "20",
                    "{d}"
                }
            }
        }
    )
}

@marc2332 marc2332 added the fix 🩹 Fixes a bug label Dec 18, 2024
@marc2332 marc2332 added this to the 0.3.0 milestone Dec 18, 2024
@marc2332 marc2332 marked this pull request as draft December 18, 2024 18:38
Copy link

Benchmark for cb8a212

Click to view benchmark
Test Base PR %
benchmarks/alignments=true size=21845 depth=8 wide=4 mode=not cached 104.0±0.89ms 102.9±0.55ms -1.06%
benchmarks/size=100001 depth=2 wide=100000 mode=not cached 26.3±0.85ms 26.3±0.87ms 0.00%
benchmarks/size=10001 depth=2 wide=10000 mode=not cached 1364.7±22.19µs 1384.4±46.56µs +1.44%
benchmarks/size=1001 depth=2 wide=1000 mode=not cached 131.3±2.71µs 132.4±2.71µs +0.84%
benchmarks/size=131071 depth=17 wide=2 mode=not cached 25.6±0.57ms 25.5±1.09ms -0.39%
benchmarks/size=16383 depth=14 wide=2 mode=not cached 1720.2±44.79µs 1731.2±37.86µs +0.64%
benchmarks/size=19531 depth=7 wide=5 mode=cached 338.4±18.44µs 335.8±15.89µs -0.77%
benchmarks/size=19531 depth=7 wide=5 mode=not cached 2.6±0.07ms 2.7±0.12ms +3.85%
benchmarks/size=4095 depth=12 wide=2 mode=not cached 416.8±136.91µs 413.7±87.92µs -0.74%
benchmarks/size=54241 depth=5 wide=15 mode=cached 287.2±50.34µs 296.0±51.36µs +3.06%
benchmarks/size=54241 depth=5 wide=15 mode=not cached 6.5±0.51ms 6.6±0.34ms +1.54%

Copy link

Benchmark for 8b00850

Click to view benchmark
Test Base PR %
benchmarks/alignments=true size=21845 depth=8 wide=4 mode=not cached 104.2±0.92ms 101.7±0.46ms -2.40%
benchmarks/size=100001 depth=2 wide=100000 mode=not cached 24.8±0.93ms 24.6±0.93ms -0.81%
benchmarks/size=10001 depth=2 wide=10000 mode=not cached 1380.7±23.13µs 1354.3±19.57µs -1.91%
benchmarks/size=1001 depth=2 wide=1000 mode=not cached 133.6±3.03µs 133.3±1.29µs -0.22%
benchmarks/size=131071 depth=17 wide=2 mode=not cached 24.4±0.52ms 24.6±0.60ms +0.82%
benchmarks/size=16383 depth=14 wide=2 mode=not cached 1716.6±35.48µs 1675.1±51.36µs -2.42%
benchmarks/size=19531 depth=7 wide=5 mode=cached 311.6±8.38µs 318.1±7.53µs +2.09%
benchmarks/size=19531 depth=7 wide=5 mode=not cached 2.5±0.02ms 2.6±0.02ms +4.00%
benchmarks/size=4095 depth=12 wide=2 mode=not cached 411.8±128.20µs 408.8±78.91µs -0.73%
benchmarks/size=54241 depth=5 wide=15 mode=cached 251.6±19.95µs 255.1±21.59µs +1.39%
benchmarks/size=54241 depth=5 wide=15 mode=not cached 6.2±0.15ms 6.3±0.12ms +1.61%

Copy link

Benchmark for 47c04f8

Click to view benchmark
Test Base PR %
benchmarks/alignments=true size=21845 depth=8 wide=4 mode=not cached 104.0±2.86ms 101.9±2.44ms -2.02%
benchmarks/size=100001 depth=2 wide=100000 mode=not cached 26.2±1.17ms 25.9±1.55ms -1.15%
benchmarks/size=10001 depth=2 wide=10000 mode=not cached 1386.2±14.40µs 1368.1±31.72µs -1.31%
benchmarks/size=1001 depth=2 wide=1000 mode=not cached 131.9±1.47µs 131.5±2.51µs -0.30%
benchmarks/size=131071 depth=17 wide=2 mode=not cached 25.4±0.80ms 25.8±0.72ms +1.57%
benchmarks/size=16383 depth=14 wide=2 mode=not cached 1710.6±55.17µs 1689.1±53.21µs -1.26%
benchmarks/size=19531 depth=7 wide=5 mode=cached 319.3±17.85µs 322.8±20.00µs +1.10%
benchmarks/size=19531 depth=7 wide=5 mode=not cached 2.6±0.04ms 2.6±0.04ms 0.00%
benchmarks/size=4095 depth=12 wide=2 mode=not cached 403.4±5.05µs 411.4±154.20µs +1.98%
benchmarks/size=54241 depth=5 wide=15 mode=cached 270.6±35.28µs 259.1±26.71µs -4.25%
benchmarks/size=54241 depth=5 wide=15 mode=not cached 6.3±0.19ms 6.3±0.14ms 0.00%

Copy link

codecov bot commented Dec 18, 2024

Codecov Report

Attention: Patch coverage is 97.89916% with 5 lines in your changes missing coverage. Please review.

Project coverage is 74.38%. Comparing base (94e7c19) to head (c61b6ed).
Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
crates/native-core/src/tree.rs 78.26% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1015      +/-   ##
==========================================
+ Coverage   74.15%   74.38%   +0.22%     
==========================================
  Files         215      216       +1     
  Lines       24685    24902     +217     
==========================================
+ Hits        18305    18523     +218     
+ Misses       6380     6379       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

Benchmark for 6465671

Click to view benchmark
Test Base PR %
benchmarks/alignments=true size=21845 depth=8 wide=4 mode=not cached 102.8±1.09ms 102.9±0.24ms +0.10%
benchmarks/size=100001 depth=2 wide=100000 mode=not cached 23.4±0.32ms 23.5±1.01ms +0.43%
benchmarks/size=10001 depth=2 wide=10000 mode=not cached 1373.2±17.71µs 1344.8±15.40µs -2.07%
benchmarks/size=1001 depth=2 wide=1000 mode=not cached 133.0±2.66µs 130.9±1.03µs -1.58%
benchmarks/size=131071 depth=17 wide=2 mode=not cached 23.2±0.29ms 23.3±0.20ms +0.43%
benchmarks/size=16383 depth=14 wide=2 mode=not cached 1714.5±96.29µs 1699.1±78.65µs -0.90%
benchmarks/size=19531 depth=7 wide=5 mode=cached 306.6±4.47µs 306.5±3.01µs -0.03%
benchmarks/size=19531 depth=7 wide=5 mode=not cached 2.5±0.01ms 2.6±0.01ms +4.00%
benchmarks/size=4095 depth=12 wide=2 mode=not cached 422.3±145.38µs 416.1±85.02µs -1.47%
benchmarks/size=54241 depth=5 wide=15 mode=cached 246.7±7.84µs 245.4±13.32µs -0.53%
benchmarks/size=54241 depth=5 wide=15 mode=not cached 6.2±0.12ms 6.3±0.11ms +1.61%

Copy link

Benchmark for 9a96a9c

Click to view benchmark
Test Base PR %
benchmarks/alignments=true size=21845 depth=8 wide=4 mode=not cached 107.6±0.82ms 104.5±0.64ms -2.88%
benchmarks/size=100001 depth=2 wide=100000 mode=not cached 24.1±0.85ms 23.9±1.24ms -0.83%
benchmarks/size=10001 depth=2 wide=10000 mode=not cached 1391.9±114.96µs 1405.5±48.79µs +0.98%
benchmarks/size=1001 depth=2 wide=1000 mode=not cached 132.1±6.28µs 134.7±1.65µs +1.97%
benchmarks/size=131071 depth=17 wide=2 mode=not cached 23.6±0.55ms 24.4±0.89ms +3.39%
benchmarks/size=16383 depth=14 wide=2 mode=not cached 1837.8±127.26µs 1674.3±67.56µs -8.90%
benchmarks/size=19531 depth=7 wide=5 mode=cached 358.5±31.98µs 315.0±21.51µs -12.13%
benchmarks/size=19531 depth=7 wide=5 mode=not cached 2.6±0.07ms 2.6±0.04ms 0.00%
benchmarks/size=4095 depth=12 wide=2 mode=not cached 416.1±94.36µs 414.2±148.51µs -0.46%
benchmarks/size=54241 depth=5 wide=15 mode=cached 253.0±26.97µs 288.1±50.86µs +13.87%
benchmarks/size=54241 depth=5 wide=15 mode=not cached 6.4±0.14ms 6.5±0.32ms +1.56%

@marc2332 marc2332 marked this pull request as ready for review December 19, 2024 18:48
@marc2332 marc2332 changed the title fix: Handle reoderdering of keyed children fix: Handle reordedering of keyed children Dec 19, 2024
Copy link

Benchmark for de8c6a0

Click to view benchmark
Test Base PR %
benchmarks/alignments=true size=21845 depth=8 wide=4 mode=not cached 107.4±0.84ms 107.1±1.00ms -0.28%
benchmarks/size=100001 depth=2 wide=100000 mode=not cached 26.3±0.88ms 26.5±1.00ms +0.76%
benchmarks/size=10001 depth=2 wide=10000 mode=not cached 1374.1±12.96µs 1386.3±25.29µs +0.89%
benchmarks/size=1001 depth=2 wide=1000 mode=not cached 133.9±1.60µs 133.5±3.53µs -0.30%
benchmarks/size=131071 depth=17 wide=2 mode=not cached 25.4±0.79ms 25.4±0.84ms 0.00%
benchmarks/size=16383 depth=14 wide=2 mode=not cached 1726.1±37.48µs 1718.3±32.41µs -0.45%
benchmarks/size=19531 depth=7 wide=5 mode=cached 332.0±18.78µs 329.2±20.09µs -0.84%
benchmarks/size=19531 depth=7 wide=5 mode=not cached 2.6±0.15ms 2.6±0.10ms 0.00%
benchmarks/size=4095 depth=12 wide=2 mode=not cached 416.1±147.18µs 413.2±104.29µs -0.70%
benchmarks/size=54241 depth=5 wide=15 mode=cached 291.9±114.62µs 286.6±42.43µs -1.82%
benchmarks/size=54241 depth=5 wide=15 mode=not cached 6.5±0.32ms 6.5±0.40ms 0.00%

@marc2332 marc2332 merged commit 3bc3698 into main Dec 19, 2024
8 checks passed
@marc2332 marc2332 deleted the fix/handle-reordering-of-keyed-children branch December 19, 2024 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix 🩹 Fixes a bug
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

1 participant