Skip to content

chore: avoid microtasks when flushing sync #15855

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

Closed
wants to merge 4 commits into from
Closed

chore: avoid microtasks when flushing sync #15855

wants to merge 4 commits into from

Conversation

trueadm
Copy link
Contributor

@trueadm trueadm commented Apr 30, 2025

This has a significant impact on our benchmark suite because we avoid creating microtasks in a sync benchmark. We previously had this logic in the codebase but it was removed in #15348

Main:

{
  benchmark: 'sbench_create_signals',
  time: '401.26',
  gc_time: '29.60'
}
{ benchmark: 'sbench_create_0to1', time: '8.17', gc_time: '0.00' }
{ benchmark: 'sbench_create_1to1', time: '29.06', gc_time: '0.59' }
{ benchmark: 'sbench_create_2to1', time: '27.08', gc_time: '0.52' }
{ benchmark: 'sbench_create_4to1', time: '25.51', gc_time: '0.61' }
{ benchmark: 'sbench_create_1000to1', time: '24.78', gc_time: '0.49' }
{ benchmark: 'sbench_create_1to2', time: '12.27', gc_time: '0.00' }
{ benchmark: 'sbench_create_1to4', time: '16.14', gc_time: '1.18' }
{ benchmark: 'sbench_create_1to8', time: '13.43', gc_time: '1.21' }
{ benchmark: 'sbench_create_1to1000', time: '4.89', gc_time: '0.00' }
{
  benchmark: 'kairo_avoidable_owned',
  time: '415.52',
  gc_time: '77.30'
}
{
  benchmark: 'kairo_avoidable_unowned',
  time: '507.39',
  gc_time: '73.81'
}
{ benchmark: 'kairo_broad_owned', time: '414.50', gc_time: '2.02' }
{ benchmark: 'kairo_broad_unowned', time: '413.50', gc_time: '2.16' }
{ benchmark: 'kairo_deep_owned', time: '181.87', gc_time: '1.93' }
{ benchmark: 'kairo_deep_unowned', time: '806.19', gc_time: '4.01' }
{ benchmark: 'kairo_diamond_owned', time: '340.28', gc_time: '34.45' }
{
  benchmark: 'kairo_diamond_unowned',
  time: '434.26',
  gc_time: '34.75'
}
{ benchmark: 'kairo_triangle_owned', time: '96.85', gc_time: '4.79' }
{
  benchmark: 'kairo_triangle_unowned',
  time: '198.79',
  gc_time: '4.57'
}
{ benchmark: 'kairo_mux_owned', time: '298.60', gc_time: '3.77' }
{ benchmark: 'kairo_mux_unowned', time: '450.16', gc_time: '3.95' }
{ benchmark: 'kairo_repeated_owned', time: '54.82', gc_time: '5.33' }
{ benchmark: 'kairo_repeated_unowned', time: '55.61', gc_time: '5.08' }
{ benchmark: 'kairo_unstable_owned', time: '88.33', gc_time: '5.46' }
{
  benchmark: 'kairo_unstable_unowned',
  time: '103.47',
  gc_time: '4.81'
}
{ benchmark: 'mol_bench_owned', time: '231.41', gc_time: '0.75' }
{ benchmark: 'mol_bench_unowned', time: '248.76', gc_time: '1.18' }

Finished reactivity benchmarks.

{ suite_time: '5902.90', suite_gc_time: '304.32' }

This PR:

{
  benchmark: 'sbench_create_signals',
  time: '295.67',
  gc_time: '79.27'
}
{ benchmark: 'sbench_create_0to1', time: '7.83', gc_time: '0.00' }
{ benchmark: 'sbench_create_1to1', time: '19.93', gc_time: '2.14' }
{ benchmark: 'sbench_create_2to1', time: '17.41', gc_time: '1.75' }
{ benchmark: 'sbench_create_4to1', time: '16.30', gc_time: '1.77' }
{ benchmark: 'sbench_create_1000to1', time: '14.97', gc_time: '2.05' }
{ benchmark: 'sbench_create_1to2', time: '9.86', gc_time: '0.60' }
{ benchmark: 'sbench_create_1to4', time: '19.46', gc_time: '6.63' }
{ benchmark: 'sbench_create_1to8', time: '15.18', gc_time: '3.71' }
{ benchmark: 'sbench_create_1to1000', time: '4.45', gc_time: '0.00' }
{ benchmark: 'kairo_avoidable_owned', time: '270.91', gc_time: '4.66' }
{
  benchmark: 'kairo_avoidable_unowned',
  time: '362.95',
  gc_time: '5.16'
}
{ benchmark: 'kairo_broad_owned', time: '408.44', gc_time: '0.00' }
{ benchmark: 'kairo_broad_unowned', time: '407.62', gc_time: '0.00' }
{ benchmark: 'kairo_deep_owned', time: '175.84', gc_time: '0.00' }
{ benchmark: 'kairo_deep_unowned', time: '805.32', gc_time: '0.00' }
{ benchmark: 'kairo_diamond_owned', time: '273.82', gc_time: '2.69' }
{ benchmark: 'kairo_diamond_unowned', time: '379.19', gc_time: '2.78' }
{ benchmark: 'kairo_triangle_owned', time: '87.13', gc_time: '0.41' }
{
  benchmark: 'kairo_triangle_unowned',
  time: '186.83',
  gc_time: '0.43'
}
{ benchmark: 'kairo_mux_owned', time: '291.71', gc_time: '1.28' }
{ benchmark: 'kairo_mux_unowned', time: '437.53', gc_time: '1.37' }
{ benchmark: 'kairo_repeated_owned', time: '44.12', gc_time: '0.21' }
{ benchmark: 'kairo_repeated_unowned', time: '45.87', gc_time: '0.21' }
{ benchmark: 'kairo_unstable_owned', time: '76.82', gc_time: '0.53' }
{ benchmark: 'kairo_unstable_unowned', time: '92.73', gc_time: '0.60' }
{ benchmark: 'mol_bench_owned', time: '230.92', gc_time: '0.24' }
{ benchmark: 'mol_bench_unowned', time: '248.28', gc_time: '0.39' }

Finished reactivity benchmarks.

{ suite_time: '5247.09', suite_gc_time: '118.88' }

Copy link

changeset-bot bot commented Apr 30, 2025

🦋 Changeset detected

Latest commit: 425a8d8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

Playground

pnpm add https://pkg.pr.new/svelte@15855

@Rich-Harris
Copy link
Member

with updated bench:compare

sbench_create_signals
  time: fastest is b (main)
    a: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 446.49ms
    b: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 439.05ms
  gc_time: fastest is b (main)
    a: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 200.65ms
    b: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 196.49ms
sbench_create_0to1
  time: fastest is b (main)
    a: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 5.00ms
    b: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 4.89ms
sbench_create_1to1
  time: fastest is a (flush-sync)
    a: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 21.81ms
    b: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 22.16ms
  gc_time: fastest is a (flush-sync)
    a: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 2.72ms
    b: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 2.73ms
sbench_create_2to1
  time: fastest is b (main)
    a: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 19.73ms
    b: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 19.48ms
  gc_time: fastest is b (main)
    a: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 2.80ms
    b: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼  2.70ms
sbench_create_4to1
  time: fastest is a (flush-sync)
    a: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 18.12ms
    b: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 18.14ms
  gc_time: fastest is b (main)
    a: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 2.78ms
    b: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼  2.70ms
sbench_create_1000to1
  time: fastest is b (main)
    a: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 16.78ms
    b: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 16.64ms
  gc_time: fastest is b (main)
    a: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 2.82ms
    b: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼  2.64ms
sbench_create_1to2
  time: fastest is a (flush-sync)
    a: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼  10.25ms
    b: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 10.61ms
  gc_time: fastest is b (main)
    a: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 0.65ms
    b: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼  0.61ms
sbench_create_1to4
  time: fastest is a (flush-sync)
    a: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼  8.36ms
    b: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 8.78ms
  gc_time: fastest is b (main)
    a: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 0.52ms
    b: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼   0.47ms
sbench_create_1to8
  time: fastest is b (main)
    a: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 6.36ms
    b: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 6.29ms
sbench_create_1to1000
  time: fastest is a (flush-sync)
    a: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼   4.65ms
    b: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 5.04ms
kairo_avoidable_owned
  time: fastest is a (flush-sync)
    a: ◼◼◼◼◼◼◼◼◼◼◼◼◼        288.04ms
    b: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 459.60ms
  gc_time: fastest is a (flush-sync)
    a: ◼                    6.73ms
    b: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 111.79ms
kairo_avoidable_unowned
  time: fastest is a (flush-sync)
    a: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼       385.36ms
    b: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 554.96ms
  gc_time: fastest is a (flush-sync)
    a: ◼                    6.74ms
    b: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 108.98ms
kairo_broad_owned
  time: fastest is a (flush-sync)
    a: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 431.42ms
    b: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 434.66ms
kairo_broad_unowned
  time: fastest is a (flush-sync)
    a: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 431.44ms
    b: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 433.16ms
kairo_deep_owned
  time: fastest is a (flush-sync)
    a: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼  189.10ms
    b: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 194.03ms
kairo_deep_unowned
  time: fastest is a (flush-sync)
    a: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 921.25ms
    b: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 928.12ms
kairo_diamond_owned
  time: fastest is a (flush-sync)
    a: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼      285.83ms
    b: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 371.12ms
  gc_time: fastest is a (flush-sync)
    a: ◼                    4.03ms
    b: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 56.06ms
kairo_diamond_unowned
  time: fastest is a (flush-sync)
    a: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼    394.52ms
    b: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 471.91ms
  gc_time: fastest is a (flush-sync)
    a: ◼                    4.06ms
    b: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 56.02ms
kairo_triangle_owned
  time: fastest is a (flush-sync)
    a: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼   93.83ms
    b: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 106.47ms
  gc_time: fastest is a (flush-sync)
    a: ◼                    0.44ms
    b: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 8.30ms
kairo_triangle_unowned
  time: fastest is a (flush-sync)
    a: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼  212.52ms
    b: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 227.08ms
  gc_time: fastest is a (flush-sync)
    a: ◼                    0.45ms
    b: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 9.08ms
kairo_mux_owned
  time: fastest is a (flush-sync)
    a: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼  313.04ms
    b: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 322.66ms
  gc_time: fastest is a (flush-sync)
    a: ◼◼◼◼◼◼◼◼             2.13ms
    b: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 5.12ms
kairo_mux_unowned
  time: fastest is a (flush-sync)
    a: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 470.57ms
    b: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 481.98ms
  gc_time: fastest is a (flush-sync)
    a: ◼◼◼◼◼◼◼◼             2.18ms
    b: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 5.36ms
kairo_repeated_owned
  time: fastest is a (flush-sync)
    a: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼     45.66ms
    b: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 57.89ms
  gc_time: fastest is a (flush-sync)
    a: ◼                    0.25ms
    b: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 7.72ms
kairo_repeated_unowned
  time: fastest is a (flush-sync)
    a: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼     46.50ms
    b: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 59.80ms
  gc_time: fastest is a (flush-sync)
    a: ◼                    0.22ms
    b: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 7.38ms
kairo_unstable_owned
  time: fastest is a (flush-sync)
    a: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼    79.44ms
    b: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 91.97ms
  gc_time: fastest is a (flush-sync)
    a: ◼◼                   0.75ms
    b: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 8.64ms
kairo_unstable_unowned
  time: fastest is a (flush-sync)
    a: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼   95.76ms
    b: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 108.02ms
  gc_time: fastest is a (flush-sync)
    a: ◼◼◼                  0.89ms
    b: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 6.66ms
mol_bench_owned
  time: fastest is a (flush-sync)
    a: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 278.60ms
    b: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 281.32ms
mol_bench_unowned
  time: fastest is a (flush-sync)
    a: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 296.31ms
    b: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 297.55ms
  gc_time: fastest is a (flush-sync)
    a: ◼◼◼◼◼                0.26ms
    b: ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼ 1.14ms

@Rich-Harris
Copy link
Member

Not sure why we need a separate boolean and a try-catch wrapper. Simpler version: #15895

@Rich-Harris
Copy link
Member

merged #15895, closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants