-
Notifications
You must be signed in to change notification settings - Fork 19
TypeScript refactoring and tooling update including performance optimizations #29
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
Conversation
…ver.mjs, bundler, docs, implemented unroll optimizations, added benchs to verify the results and updated documentation plus package.json including version bump
…ecked that node:* and .js imports were stable with 14.x
Netlify fails probably because
Min: Would have been the same with a modern version of rollup: |
@kyro, just a note that I'm very very busy with high-priority work stuff, and while this is also work stuff and generally looks excellent, I haven't finished the review -- but your work is highly appreciated, and I hope to get to it this week. |
Thank you for your response @padenot . No worries, I feel you. I know these kind of situations too well. Thank you for taking the time to work on this anyway. That's highly appreciated as well! I hope your stress level is not skyrocketing. Please take your time -- there's absolutely no need to hurry. I'm fine with my codebase and not blocked in any way. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My review doesn't mean much, but at least you know one more person has looked over this.
Looks good overall. The line changes look deceptively large, this is actually a pretty easy review (although I did not look over the bench files, readme, or linting files changes). I didn't see anything that would explicitly prevent this from being merged as is.
Awesome work @kyr0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks perfect, I'll push an additional commit and publish it on npm. Thanks a ton for doing this, and sorry about the delay, I was super busy and completely forgot about it.
README.md
Outdated
@@ -68,6 +68,18 @@ allows running the build step and copying the file to allow the example to work. | |||
|
|||
allows rebuilding the documentation. | |||
|
|||
## Performance Benchmarks | |||
|
|||
As of version `0.4.0`, the whole codebase has been ported to TypeScript, tooling has been modernized and dependencies were updated. The pakcage is now also marked as side-effect free, which allows bundlers to tree-shake the code for unused symbols when imported. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo on package.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed it.
README.md
Outdated
|
||
Alongside these updates, two performance optimizations were introduced: | ||
|
||
- `_copy` has been optimized by a loop factor of 16. [`bench`](bench/deinterleave-bench.html) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... optimized by unrolling with ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also fixed that one.
4f97e22
to
effbf98
Compare
I had to bump the node versions from an antediluvian version to the oldest supported both in GitHub Actions and netlify, and we're good, I'll go and publish the package now. Thanks a lot, again! |
Wonderful! I'm so happy that you like the changes! :) I'll update my project and switch to the new version, providing you with an "in the wild" test result very soon! And I'm glad you're not as stressed anymore! |
Looks like a nice refactor. The only note I have is it would be nice to understand when the fast path of |
Yeah we can make this clearer. Essentially:
E.g. if you're pushing 6 values at a time, and it's the full array, and your capacity is 28 (for the sake of the example), it will go:
it follows that if you use a ring buffer capacity that is a multiple of your enqueue size, and those are fixed (which is often the case in audio), you hit the fastest path 100% of the time. One can keep count externally, because the logic isn't particularly complex, but we could add a method that would return if the next write of |
I would err on the side of keeping the library simple. Thanks for the information! |
With this PR, I'm providing the source code, tests, docs, and benchs for the full refactoring of the library to TypeScript.
TL;DR: I know it's a huge PR, but I made sure that it's easy to compare line-by-line (!)
I'll keep this description short, as the code speaks for itself; here's a short list of changes including reasoning:
src
is the standard for TypeScript projects. I moved the code there, added all types, fixed a few minor issues like grammar, addedtsconfig.json
matching the target language level, and removed the JSDoc parameter type annotations to prevent duplicate type definitions. Those doc types are inferred bytypedoc
, which is now used instead ofjsdoc
, produces similar output but supports TypeScript.eslint
was outdated. While updating, I also upgraded the configuration format to the new flat format, maintaining all configuration values "as is". For a well-typed experience, I chosetypescript-eslint
.rollup
has a critical security vulnerability (XSS); it was audit fixed alongside usingpkgroll
for packaging, which reduces the complexity of the build process. The "exports" standard inpackage.json
is now in place and defines the build process with zero additional configuration.sideEffects
are set to false inpackage.json
. This allows bundlers in user-land code that imports this packages code to tree-shake any symbol out that isn't used which helps reducing bundle size in end-user products.bench
, the benchmarks have been comitted.server.js
has been modernized and all deprecated APIs were replaced by modern solutions.engines
inpackage.json
were updated to 14.x, respective npm 8.x minimum.&&
traditionally leads to issues on non-unix systems,build
has been separated inbuild
andpostbuild
inpackage.json
README.md
has been updated and a new section has been added for Performance Benchmarks and the 0.4.0 changes.0.4.0
seemed reasonable because of slight changes of implementation details, to prevent behaviour to change in downstream projects, which an update to 0.3.x would introduce.Verification Steps:
npm i
to update local dependencies.unit testing (all green)
example testing (it works in all engines)
linting (all green)
Note 1:
One change that
pkgroll
introduces is that there is nodist/index.es.js
anymore as it is replaced bydist/index.mjs
which serves its purpose (and is referenced inpackage.json
as by the current community standard).Note 2:
In the verification, I think I found a little bug. https://github.com/padenot/ringbuf.js/pull/29/files#diff-49be8ccb783567bb711d67edf34f746ae9bd8e7e5b1110a498344bf8e9969f6cR56 Would be cool if you could please double-check if the original code was intended as-is, and if my "fix" is fine or would lead to diverging verification behaviour.
I'm looking forward to your feedback!
p.s.: This PR replaces both other PRs which become automatically obsolete and IMHO fixes #22 - making this project 100% green for the time being.