Skip to content

chore: improve old value implementation performance #15854

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

trueadm
Copy link
Contributor

@trueadm trueadm commented Apr 30, 2025

This improves the signal runtime performance by opting for a linked list rather than a Map for storing old values. In theory a Map should be O(1) for lookups, but they come with overhead in terms when both setting a value and when clearing the Map down. Instead, using a linked list avoids this overhead except in the case where there might be many signal changes in the same update – in which case, maybe we should still opt to use a Map for those cases. Here are the benchmark results:

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: '296.43',
  gc_time: '78.94'
}
{ benchmark: 'sbench_create_0to1', time: '7.96', gc_time: '0.00' }
{ benchmark: 'sbench_create_1to1', time: '19.28', gc_time: '1.72' }
{ benchmark: 'sbench_create_2to1', time: '17.12', gc_time: '1.84' }
{ benchmark: 'sbench_create_4to1', time: '15.60', gc_time: '1.78' }
{ benchmark: 'sbench_create_1000to1', time: '14.50', gc_time: '1.63' }
{ benchmark: 'sbench_create_1to2', time: '9.62', gc_time: '0.53' }
{ benchmark: 'sbench_create_1to4', time: '19.26', gc_time: '6.70' }
{ benchmark: 'sbench_create_1to8', time: '14.69', gc_time: '3.57' }
{ benchmark: 'sbench_create_1to1000', time: '4.36', gc_time: '0.00' }
{
  benchmark: 'kairo_avoidable_owned',
  time: '359.36',
  gc_time: '67.77'
}
{
  benchmark: 'kairo_avoidable_unowned',
  time: '450.11',
  gc_time: '67.10'
}
{ benchmark: 'kairo_broad_owned', time: '416.18', gc_time: '1.68' }
{ benchmark: 'kairo_broad_unowned', time: '414.42', gc_time: '2.45' }
{ benchmark: 'kairo_deep_owned', time: '178.57', gc_time: '1.29' }
{ benchmark: 'kairo_deep_unowned', time: '823.22', gc_time: '3.19' }
{ benchmark: 'kairo_diamond_owned', time: '310.31', gc_time: '31.70' }
{
  benchmark: 'kairo_diamond_unowned',
  time: '406.96',
  gc_time: '31.66'
}
{ benchmark: 'kairo_triangle_owned', time: '93.90', gc_time: '5.69' }
{
  benchmark: 'kairo_triangle_unowned',
  time: '199.99',
  gc_time: '6.23'
}
{ benchmark: 'kairo_mux_owned', time: '299.27', gc_time: '3.63' }
{ benchmark: 'kairo_mux_unowned', time: '451.08', gc_time: '3.53' }
{ benchmark: 'kairo_repeated_owned', time: '51.61', gc_time: '4.41' }
{ benchmark: 'kairo_repeated_unowned', time: '52.58', gc_time: '4.54' }
{ benchmark: 'kairo_unstable_owned', time: '83.56', gc_time: '5.82' }
{
  benchmark: 'kairo_unstable_unowned',
  time: '101.41',
  gc_time: '5.96'
}
{ benchmark: 'mol_bench_owned', time: '232.01', gc_time: '0.80' }
{ benchmark: 'mol_bench_unowned', time: '249.05', gc_time: '1.24' }

Finished reactivity benchmarks.

{ suite_time: '5592.41', suite_gc_time: '345.40' }

Copy link

changeset-bot bot commented Apr 30, 2025

🦋 Changeset detected

Latest commit: cc976d8

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@15854

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.

1 participant