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

performance idea: rewrite to "set iterator with while" or back to Array #2

Open
betula opened this issue Aug 10, 2022 · 1 comment
Open

Comments

@betula
Copy link
Member

betula commented Aug 10, 2022

  run = (unsubs) => (
    // can unsubs be modified in run functions?
    unsubs.forEach(fn => fn()), // performance problem here (for of more quick)
    unsubs.clear()
  ),

"for of" perf problem

And return "detach" function no have a reason in most cases:

  attach = (unsubs, fn) => (
    (fn || (fn = unsubs, unsubs = context_unsubs)), <---------- remove "||" performance reason
    unsubs && unsubs.add(fn),
    () => unsubs.delete(fn) // <--------------- remove it performance and size reason
  ),

It should be super small and super fast!

p.s.
May be rewrite back to Array from Set.
May be remove "unsubscriber" function (it's so long name) and type in documentation what it is an array.

@betula
Copy link
Member Author

betula commented Aug 12, 2022

node.js:
for of array        60.82   56.2 	  54.75 	54.65 	53.88 	54.93 	55.02 	54.89 	53.83 	55.12
array.forEach       62      55.68 	54.27 	54.64 	55.37 	55.1 	  54.24 	55.04 	55.68 	54.69
for of set          56.1    54.94 	56.14 	55.66 	54.65 	55.15 	55.7 	  55.78 	54.72 	55.42
set.forEach         152.21 	150.54 	148.34 	148.64 	150.01 	149.59 	148.88 	148.59 	149.59 	149.52
for with len        54.54 	53.81 	54.9 	  55.04 	53.62 	54.18 	55.01 	54.69 	53.71 	54.11
for                 55.78 	54.82 	53.97 	54.1 	  55.05 	55.17 	53.94 	54.16 	55.13 	55.44
set iterator while  60.01 	58.52 	59.45 	59.54 	58.48 	58.33 	59.46 	59.7 	  58.67 	58.43

bun:
for of array        51.15 	41.57 	42.46 	42.7 	  42.02 	41.88 	43.15 	41.8 	  41.45 	41.39
array.forEach       39.03 	35.45 	34.47 	35.14 	34.35 	35.01 	34.24 	34.33 	34.34 	34.2
for of set          50.38 	46.1 	  45.83 	48.84 	45.58 	46.97 	46.97 	47.25 	49.89 	46.47
set.forEach         40.89 	35.84 	33.92 	33.65 	32.99 	32.81 	33.3 	  32.8 	  32.76 	32.77
for with len        26.53 	26.14 	26.51 	26.87 	26.17 	25.63 	25.66 	25.59 	25.69 	25.63
for                 27.42 	26.55 	26.07 	25.76 	25.67 	25.58 	25.61 	25.62 	25.61 	25.56
set iterator while  37.77 	35.27 	35.27 	35.19 	35.17 	35.17 	35.43 	36.24 	36.21 	36.41

https://github.com/re-js/evemin/blob/2544cecc6f1c7da98464b0179f870e3bc6e80810/perf_test.js#L6-L26

@betula betula changed the title performance: rewrite to "for of" performance: rewrite to "set iterator with while" or back to Array Aug 12, 2022
@betula betula changed the title performance: rewrite to "set iterator with while" or back to Array performance idea: rewrite to "set iterator with while" or back to Array Aug 12, 2022
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

No branches or pull requests

1 participant