Title: lib: optimize FixedQueue by reusing one segment by gurgunday · Pull Request #60031 · nodejs/node · GitHub
Open Graph Title: lib: optimize FixedQueue by reusing one segment by gurgunday · Pull Request #60031 · nodejs/node
X Title: lib: optimize FixedQueue by reusing one segment by gurgunday · Pull Request #60031 · nodejs/node
Description: Benchmarks: main: node % ./node benchmark/run.js --filter fixed-queue util util/fixed-queue-oscillate.js util/fixed-queue-oscillate.js cycles=5000: 240,760,722.06068513 util/fixed-queue.js util/fixed-queue.js n=100000: 30,605,608.47775355 branch: node % ./node benchmark/run.js --filter fixed-queue util util/fixed-queue-oscillate.js util/fixed-queue-oscillate.js cycles=5000: 283,339,287.4243814 util/fixed-queue.js util/fixed-queue.js n=100000: 32,606,927.0808029 When the head segment fills, we reuse a “spare” FixedCircularBuffer if available; when a segment becomes empty, we reset it and stash it as the spare instead of wasting it. This cuts allocations/GC especially when the queue oscillates between N and N+1 segments, which is more than likely to be the case in real life scenarios where Events/Promises/Tasks are emitted/created and consumed in bursts. We only call reset() when reusing a spare (not for a freshly allocated buffer). And finally, there is no behavior change: we have the same data structure (linked fixed-size circular buffers), same invariants (one-slot-wasted), same FIFO semantics and API. Capacity per segment stays kSize - 1, so overall capacity is unchanged.
Open Graph Description: Benchmarks: main: node % ./node benchmark/run.js --filter fixed-queue util util/fixed-queue-oscillate.js util/fixed-queue-oscillate.js cycles=5000: 240,760,722.06068513 util/fixed-queue.js util/fix...
X Description: Benchmarks: main: node % ./node benchmark/run.js --filter fixed-queue util util/fixed-queue-oscillate.js util/fixed-queue-oscillate.js cycles=5000: 240,760,722.06068513 util/fixed-queue.js util/fix...
Opengraph URL: https://github.com/nodejs/node/pull/60031
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:24b8bf60-4893-98d1-d04f-03bd8d09e278 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 9CE4:13DA2D:FDF52B:1701D87:6A4CCE59 |
| html-safe-nonce | 3b65270311db724d56d7252fd810397d3459e2a6ae97556762bbb1e3afb2f92e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5Q0U0OjEzREEyRDpGREY1MkI6MTcwMUQ4Nzo2QTRDQ0U1OSIsInZpc2l0b3JfaWQiOiI1MTY3MzE4NTA5MDAwOTA0MjgxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 681d87b004e6566b9b121ab08c2beda6a564faeb824ddc39d6bd36fb8f141532 |
| hovercard-subject-tag | pull_request:2866282164 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/nodejs/node/pull/60031/files |
| twitter:image | https://avatars.githubusercontent.com/u/74139498?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/74139498?s=400&v=4 |
| og:image:alt | Benchmarks: main: node % ./node benchmark/run.js --filter fixed-queue util util/fixed-queue-oscillate.js util/fixed-queue-oscillate.js cycles=5000: 240,760,722.06068513 util/fixed-queue.js util/fix... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | ee8a9d18044a05fe2d57b9ae797da38c8be34effb03f015f7c42e94770d28a1b |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/nodejs/node git https://github.com/nodejs/node.git |
| octolytics-dimension-user_id | 9950313 |
| octolytics-dimension-user_login | nodejs |
| octolytics-dimension-repository_id | 27193779 |
| octolytics-dimension-repository_nwo | nodejs/node |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 27193779 |
| octolytics-dimension-repository_network_root_nwo | nodejs/node |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | f84814acc6f036583fd43463f5847a846243d2a4 |
| ui-target | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width