performance-helpers 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (347) hide show
  1. package/.eslintrc.cjs +22 -0
  2. package/.nojekyll +0 -0
  3. package/.prettierrc +6 -0
  4. package/CONTRIBUTING.md +178 -0
  5. package/LICENSE.md +21 -0
  6. package/README.md +194 -0
  7. package/assets/1_Caching.md +4 -0
  8. package/assets/2_Parallelizing.md +18 -0
  9. package/assets/3_Logging.md +3 -0
  10. package/assets/404.md +3 -0
  11. package/assets/4_Utils.md +10 -0
  12. package/assets/logo.png +0 -0
  13. package/assets/navigation.md +10 -0
  14. package/bench/README.md +97 -0
  15. package/bench/results.json +94 -0
  16. package/bench/results.md +233 -0
  17. package/bench/run.js +2639 -0
  18. package/bench/worker.js +43 -0
  19. package/docs/README.md +38 -0
  20. package/docs/docs-typedoc.json +38714 -0
  21. package/docs/helpers/constants/README.md +34 -0
  22. package/docs/helpers/constants/variables/DEFAULT_AUTOSCALE_BACKOFF_MAX_MULTIPLIER.md +9 -0
  23. package/docs/helpers/constants/variables/DEFAULT_AUTOSCALE_COOLDOWN_MS.md +9 -0
  24. package/docs/helpers/constants/variables/DEFAULT_AUTOSCALE_INTERVAL_MS.md +9 -0
  25. package/docs/helpers/constants/variables/DEFAULT_AUTOSCALE_MIN_INTERVAL_MS.md +9 -0
  26. package/docs/helpers/constants/variables/DEFAULT_BACKPRESSURE_QUEUE_CAPACITY.md +9 -0
  27. package/docs/helpers/constants/variables/DEFAULT_BACKPRESSURE_REFILL_INTERVAL_MS.md +9 -0
  28. package/docs/helpers/constants/variables/DEFAULT_BATCH_MAX_SIZE.md +9 -0
  29. package/docs/helpers/constants/variables/DEFAULT_CACHE_DEFAULT_TTL_MS.md +9 -0
  30. package/docs/helpers/constants/variables/DEFAULT_CACHE_MAX_POOL_SIZE.md +9 -0
  31. package/docs/helpers/constants/variables/DEFAULT_CACHE_MAX_WEIGHT_BYTES.md +9 -0
  32. package/docs/helpers/constants/variables/DEFAULT_HISTOGRAM_BUCKET_COUNT.md +9 -0
  33. package/docs/helpers/constants/variables/DEFAULT_HISTOGRAM_MAX_VALUE.md +9 -0
  34. package/docs/helpers/constants/variables/DEFAULT_MAX_CLEANUP_PER_TICK.md +9 -0
  35. package/docs/helpers/constants/variables/DEFAULT_QUEUE_CAPACITY.md +9 -0
  36. package/docs/helpers/constants/variables/DEFAULT_REAPER_MIN_INTERVAL_MS.md +9 -0
  37. package/docs/helpers/constants/variables/DEFAULT_REFILL_INTERVAL_MS.md +9 -0
  38. package/docs/helpers/constants/variables/DEFAULT_RETRY_BASE_DELAY_MS.md +9 -0
  39. package/docs/helpers/constants/variables/DEFAULT_RETRY_MAX_DELAY_MS.md +9 -0
  40. package/docs/helpers/constants/variables/DEFAULT_TIMEOUT_MS.md +9 -0
  41. package/docs/helpers/constants/variables/ENCODE_CACHE_LARGE_KEY_LENGTH.md +9 -0
  42. package/docs/helpers/constants/variables/MAX_DEEP_EQUAL_DEPTH.md +9 -0
  43. package/docs/helpers/constants/variables/MS_PER_MIN.md +9 -0
  44. package/docs/helpers/constants/variables/MS_PER_SEC.md +9 -0
  45. package/docs/helpers/constants/variables/default.md +103 -0
  46. package/docs/helpers/jsdoc-types/README.md +33 -0
  47. package/docs/helpers/jsdoc-types/interfaces/BufferDecoder.md +23 -0
  48. package/docs/helpers/jsdoc-types/interfaces/BufferEncoder.md +23 -0
  49. package/docs/helpers/jsdoc-types/interfaces/CacheNode.md +43 -0
  50. package/docs/helpers/jsdoc-types/interfaces/CommonPoolOptions.md +31 -0
  51. package/docs/helpers/jsdoc-types/interfaces/PendingResponseEntry.md +51 -0
  52. package/docs/helpers/jsdoc-types/interfaces/PostMessageOptions.md +39 -0
  53. package/docs/helpers/jsdoc-types/interfaces/PowerBatchOptions.md +13 -0
  54. package/docs/helpers/jsdoc-types/interfaces/PowerCacheOptions.md +115 -0
  55. package/docs/helpers/jsdoc-types/interfaces/PowerChunkingOptions.md +31 -0
  56. package/docs/helpers/jsdoc-types/interfaces/PowerCircuitOptions.md +45 -0
  57. package/docs/helpers/jsdoc-types/interfaces/PowerDeadlineOptions.md +101 -0
  58. package/docs/helpers/jsdoc-types/interfaces/PowerDeferOptions.md +13 -0
  59. package/docs/helpers/jsdoc-types/interfaces/PowerEventBusOptions.md +19 -0
  60. package/docs/helpers/jsdoc-types/interfaces/PowerLatchOptions.md +23 -0
  61. package/docs/helpers/jsdoc-types/interfaces/PowerLoggerOptions.md +51 -0
  62. package/docs/helpers/jsdoc-types/interfaces/PowerObserverOptions.md +25 -0
  63. package/docs/helpers/jsdoc-types/interfaces/PowerPoolOptions.md +85 -0
  64. package/docs/helpers/jsdoc-types/interfaces/PowerQueueOptions.md +13 -0
  65. package/docs/helpers/jsdoc-types/interfaces/PowerRetryOptions.md +83 -0
  66. package/docs/helpers/jsdoc-types/interfaces/PowerSlidingWindowOptions.md +19 -0
  67. package/docs/helpers/jsdoc-types/interfaces/PowerTTLMapOptions.md +27 -0
  68. package/docs/helpers/jsdoc-types/interfaces/PowerThrottleOptions.md +31 -0
  69. package/docs/helpers/jsdoc-types/interfaces/WorkerObj.md +55 -0
  70. package/docs/helpers/powerBackpressure/README.md +17 -0
  71. package/docs/helpers/powerBackpressure/classes/PowerBackpressure.md +368 -0
  72. package/docs/helpers/powerBatch/README.md +17 -0
  73. package/docs/helpers/powerBatch/classes/PowerBatch.md +139 -0
  74. package/docs/helpers/powerBuffer/README.md +26 -0
  75. package/docs/helpers/powerBuffer/functions/b2o.md +25 -0
  76. package/docs/helpers/powerBuffer/functions/o2b.md +23 -0
  77. package/docs/helpers/powerBuffer/functions/o2u8.md +33 -0
  78. package/docs/helpers/powerBuffer/functions/u82o.md +30 -0
  79. package/docs/helpers/powerBulkhead/README.md +17 -0
  80. package/docs/helpers/powerBulkhead/classes/PowerBulkhead.md +302 -0
  81. package/docs/helpers/powerCache/README.md +29 -0
  82. package/docs/helpers/powerCache/classes/PowerCache.md +933 -0
  83. package/docs/helpers/powerCache/classes/PowerMemoizer.md +244 -0
  84. package/docs/helpers/powerCache/classes/PowerTimedCache.md +302 -0
  85. package/docs/helpers/powerCache/functions/simpleArgsKey.md +31 -0
  86. package/docs/helpers/powerChunking/README.md +17 -0
  87. package/docs/helpers/powerChunking/classes/PowerChunker.md +78 -0
  88. package/docs/helpers/powerCircuit/README.md +23 -0
  89. package/docs/helpers/powerCircuit/classes/PowerCircuit.md +167 -0
  90. package/docs/helpers/powerDeadline/README.md +23 -0
  91. package/docs/helpers/powerDeadline/classes/PowerDeadline.md +88 -0
  92. package/docs/helpers/powerDefer/README.md +17 -0
  93. package/docs/helpers/powerDefer/classes/PowerDefer.md +134 -0
  94. package/docs/helpers/powerEventBus/README.md +23 -0
  95. package/docs/helpers/powerEventBus/classes/PowerEventBus.md +330 -0
  96. package/docs/helpers/powerHistogram/README.md +17 -0
  97. package/docs/helpers/powerHistogram/classes/PowerHistogram.md +285 -0
  98. package/docs/helpers/powerLatch/README.md +17 -0
  99. package/docs/helpers/powerLatch/classes/PowerLatch.md +264 -0
  100. package/docs/helpers/powerLogger/README.md +17 -0
  101. package/docs/helpers/powerLogger/classes/PowerLogger.md +290 -0
  102. package/docs/helpers/powerObserver/README.md +23 -0
  103. package/docs/helpers/powerObserver/classes/PowerObserver.md +213 -0
  104. package/docs/helpers/powerPermitGate/README.md +11 -0
  105. package/docs/helpers/powerPermitGate/classes/PowerPermitGate.md +248 -0
  106. package/docs/helpers/powerPool/README.md +36 -0
  107. package/docs/helpers/powerPool/classes/PowerPool.md +973 -0
  108. package/docs/helpers/powerPool/classes/PowerPoolShutdownError.md +67 -0
  109. package/docs/helpers/powerQueue/README.md +11 -0
  110. package/docs/helpers/powerQueue/classes/PowerQueue.md +302 -0
  111. package/docs/helpers/powerRateLimit/README.md +17 -0
  112. package/docs/helpers/powerRateLimit/classes/PowerRateLimit.md +187 -0
  113. package/docs/helpers/powerRetry/README.md +23 -0
  114. package/docs/helpers/powerRetry/classes/PowerRetry.md +106 -0
  115. package/docs/helpers/powerScheduler/README.md +11 -0
  116. package/docs/helpers/powerScheduler/classes/PowerScheduler.md +135 -0
  117. package/docs/helpers/powerSemaphore/README.md +17 -0
  118. package/docs/helpers/powerSemaphore/classes/PowerSemaphore.md +173 -0
  119. package/docs/helpers/powerSlidingWindow/README.md +11 -0
  120. package/docs/helpers/powerSlidingWindow/classes/PowerSlidingWindow.md +83 -0
  121. package/docs/helpers/powerSubscriberSet/README.md +15 -0
  122. package/docs/helpers/powerSubscriberSet/classes/PowerSubscriberSet.md +251 -0
  123. package/docs/helpers/powerSubscriberSet/functions/cleanupWeakRefs.md +21 -0
  124. package/docs/helpers/powerTTLMap/README.md +17 -0
  125. package/docs/helpers/powerTTLMap/classes/PowerTTLMap.md +326 -0
  126. package/docs/helpers/powerThrottle/README.md +17 -0
  127. package/docs/helpers/powerThrottle/classes/PowerThrottle.md +216 -0
  128. package/docs/index/README.md +205 -0
  129. package/docs/utils/errors/README.md +12 -0
  130. package/docs/utils/errors/functions/formatErrorObj.md +30 -0
  131. package/docs/utils/errors/functions/normalizeError.md +50 -0
  132. package/docs/utils/now/README.md +19 -0
  133. package/docs/utils/now/functions/measureAsync.md +37 -0
  134. package/docs/utils/now/functions/measureSync.md +54 -0
  135. package/docs/utils/now/functions/nowMs.md +24 -0
  136. package/guides/autoscale.md +80 -0
  137. package/guides/errors.md +41 -0
  138. package/guides/metaGuide.md +440 -0
  139. package/guides/now.md +56 -0
  140. package/guides/powerBackpressure.md +110 -0
  141. package/guides/powerBatch.md +82 -0
  142. package/guides/powerBuffer.md +86 -0
  143. package/guides/powerBulkhead.md +61 -0
  144. package/guides/powerCache.md +269 -0
  145. package/guides/powerChunking.md +130 -0
  146. package/guides/powerCircuit.md +84 -0
  147. package/guides/powerDeadline.md +99 -0
  148. package/guides/powerDefer.md +56 -0
  149. package/guides/powerEventBus.md +89 -0
  150. package/guides/powerHistogram.md +71 -0
  151. package/guides/powerLatch.md +94 -0
  152. package/guides/powerLogger.md +129 -0
  153. package/guides/powerObserver.md +65 -0
  154. package/guides/powerPermitGate.md +52 -0
  155. package/guides/powerPool.md +321 -0
  156. package/guides/powerQueue.md +112 -0
  157. package/guides/powerRateLimit.md +37 -0
  158. package/guides/powerRetry.md +54 -0
  159. package/guides/powerScheduler.md +41 -0
  160. package/guides/powerSemaphore.md +65 -0
  161. package/guides/powerSlidingWindow.md +63 -0
  162. package/guides/powerSubscriberSet.md +48 -0
  163. package/guides/powerTTLMap.md +58 -0
  164. package/guides/powerThrottle.md +152 -0
  165. package/index.html +57 -0
  166. package/package.json +81 -0
  167. package/results.json +6692 -0
  168. package/scripts/find-missing-jsdoc.js +62 -0
  169. package/scripts/modernize-optional-chaining.cjs +36 -0
  170. package/scripts/pool-debug.mjs +29 -0
  171. package/scripts/repro_powercache.js +14 -0
  172. package/scripts/static-audit-exports.cjs +93 -0
  173. package/scripts/static-audit-exports.json +518 -0
  174. package/src/helpers/constants.js +69 -0
  175. package/src/helpers/jsdoc-types.js +221 -0
  176. package/src/helpers/powerBackpressure.js +182 -0
  177. package/src/helpers/powerBatch.js +161 -0
  178. package/src/helpers/powerBuffer.js +161 -0
  179. package/src/helpers/powerBulkhead.js +203 -0
  180. package/src/helpers/powerCache.js +1740 -0
  181. package/src/helpers/powerChunking.js +340 -0
  182. package/src/helpers/powerCircuit.js +160 -0
  183. package/src/helpers/powerDeadline.js +181 -0
  184. package/src/helpers/powerDefer.js +100 -0
  185. package/src/helpers/powerEventBus.js +405 -0
  186. package/src/helpers/powerHistogram.js +174 -0
  187. package/src/helpers/powerLatch.js +247 -0
  188. package/src/helpers/powerLogger.js +348 -0
  189. package/src/helpers/powerObserver.js +146 -0
  190. package/src/helpers/powerPermitGate.js +142 -0
  191. package/src/helpers/powerPool.js +2793 -0
  192. package/src/helpers/powerQueue.js +253 -0
  193. package/src/helpers/powerRateLimit.js +273 -0
  194. package/src/helpers/powerRetry.js +114 -0
  195. package/src/helpers/powerScheduler.js +91 -0
  196. package/src/helpers/powerSemaphore.js +94 -0
  197. package/src/helpers/powerSlidingWindow.js +86 -0
  198. package/src/helpers/powerSubscriberSet.js +260 -0
  199. package/src/helpers/powerTTLMap.js +253 -0
  200. package/src/helpers/powerThrottle.js +171 -0
  201. package/src/index.js +27 -0
  202. package/src/utils/errors.js +45 -0
  203. package/src/utils/now.js +129 -0
  204. package/test/powerBackpressure.test.js +114 -0
  205. package/test/powerBatch.branches.extra.test.js +122 -0
  206. package/test/powerBatch.test.js +79 -0
  207. package/test/powerBuffer.test.js +125 -0
  208. package/test/powerBulkhead.test.js +210 -0
  209. package/test/powerCache.branches.test.js +233 -0
  210. package/test/powerCache.bulk.test.js +31 -0
  211. package/test/powerCache.getorset.test.js +110 -0
  212. package/test/powerCache.hitRate.test.js +35 -0
  213. package/test/powerCache.inflight.test.js +24 -0
  214. package/test/powerCache.iterator.test.js +18 -0
  215. package/test/powerCache.misses.test.js +52 -0
  216. package/test/powerCache.more.test.js +118 -0
  217. package/test/powerCache.test.js +37 -0
  218. package/test/powerCache.timeout.test.js +25 -0
  219. package/test/powerCache.touch.test.js +46 -0
  220. package/test/powerChunking.branches.extra.test.js +155 -0
  221. package/test/powerChunking.errors.test.js +177 -0
  222. package/test/powerChunking.test.js +39 -0
  223. package/test/powerCircuit.observability.test.js +71 -0
  224. package/test/powerCircuit.test.js +74 -0
  225. package/test/powerDeadline.test.js +140 -0
  226. package/test/powerDefer.test.js +55 -0
  227. package/test/powerErrors.test.js +32 -0
  228. package/test/powerEventBus.branches.extra.test.js +70 -0
  229. package/test/powerEventBus.extra.test.js +72 -0
  230. package/test/powerEventBus.max.test.js +43 -0
  231. package/test/powerEventBus.more.test.js +121 -0
  232. package/test/powerEventBus.once_off.test.js +17 -0
  233. package/test/powerEventBus.test.js +74 -0
  234. package/test/powerEventBus.uncovered.test.js +57 -0
  235. package/test/powerEventBus.weak.test.js +18 -0
  236. package/test/powerHistogram.test.js +73 -0
  237. package/test/powerLatch.branches.extra.test.js +115 -0
  238. package/test/powerLatch.test.js +57 -0
  239. package/test/powerLogger.branches.test.js +98 -0
  240. package/test/powerLogger.formatter.name.test.js +58 -0
  241. package/test/powerLogger.json.test.js +88 -0
  242. package/test/powerLogger.output.test.js +81 -0
  243. package/test/powerLogger.table.debug.test.js +77 -0
  244. package/test/powerLogger.test.js +59 -0
  245. package/test/powerMemoizer.memoize.test.js +100 -0
  246. package/test/powerMemoizer.test.js +85 -0
  247. package/test/powerObserver.test.js +129 -0
  248. package/test/powerPermitGate.test.js +66 -0
  249. package/test/powerPool.autoTransfer.test.js +100 -0
  250. package/test/powerPool.autoscale.extra.test.js +88 -0
  251. package/test/powerPool.autoscale.test.js +136 -0
  252. package/test/powerPool.awaitDefaultTimeout.test.js +52 -0
  253. package/test/powerPool.awaitTimeout.test.js +22 -0
  254. package/test/powerPool.batch.test.js +170 -0
  255. package/test/powerPool.branches.extra2.test.js +42 -0
  256. package/test/powerPool.branches.test.js +102 -0
  257. package/test/powerPool.browser.messageerror.test.js +45 -0
  258. package/test/powerPool.correlation.test.js +26 -0
  259. package/test/powerPool.correlationId.test.js +63 -0
  260. package/test/powerPool.dispose.test.js +49 -0
  261. package/test/powerPool.drain.test.js +57 -0
  262. package/test/powerPool.events.test.js +131 -0
  263. package/test/powerPool.more.extra.test.js +99 -0
  264. package/test/powerPool.more.test.js +283 -0
  265. package/test/powerPool.node.messageerror.test.js +46 -0
  266. package/test/powerPool.postMessage.promise.test.js +83 -0
  267. package/test/powerPool.queueHigh.test.js +55 -0
  268. package/test/powerPool.queueSaturation.test.js +51 -0
  269. package/test/powerPool.rapidResize.test.js +55 -0
  270. package/test/powerPool.resize.overload.test.js +65 -0
  271. package/test/powerPool.resize.test.js +70 -0
  272. package/test/powerPool.shutdown.test.js +38 -0
  273. package/test/powerPool.stats.test.js +40 -0
  274. package/test/powerPool.stopThePress.test.js +94 -0
  275. package/test/powerPool.terminateShutdown.test.js +22 -0
  276. package/test/powerPool.test.js +525 -0
  277. package/test/powerPool.timers.test.js +55 -0
  278. package/test/powerPool.uncovered.test.js +407 -0
  279. package/test/powerPool.workerId.test.js +47 -0
  280. package/test/powerQueue.iterators.test.js +67 -0
  281. package/test/powerQueue.saturation.test.js +18 -0
  282. package/test/powerQueue.test.js +48 -0
  283. package/test/powerQueue.unshiftMany.test.js +49 -0
  284. package/test/powerRateLimit.atomic.test.js +80 -0
  285. package/test/powerRateLimit.extra.test.js +145 -0
  286. package/test/powerRateLimit.functions.test.js +106 -0
  287. package/test/powerRateLimit.test.js +38 -0
  288. package/test/powerRetry.attemptTimeout.test.js +51 -0
  289. package/test/powerRetry.test.js +121 -0
  290. package/test/powerScheduler.test.js +126 -0
  291. package/test/powerSemaphore.test.js +108 -0
  292. package/test/powerSlidingWindow.pool.test.js +55 -0
  293. package/test/powerSlidingWindow.test.js +25 -0
  294. package/test/powerSubscriberSet.test.js +125 -0
  295. package/test/powerTTLMap.test.js +125 -0
  296. package/test/powerThrottle.pool.test.js +54 -0
  297. package/test/powerThrottle.refill.test.js +22 -0
  298. package/test/powerThrottle.reserve.test.js +46 -0
  299. package/test/powerThrottle.test.js +45 -0
  300. package/test/powerTimedCache.test.js +73 -0
  301. package/test/umd.bundle.branches.test.js +100 -0
  302. package/test/umd.bundle.cache-timers.test.js +48 -0
  303. package/test/umd.bundle.exhaustive.test.js +158 -0
  304. package/test/umd.bundle.fuzz.test.js +86 -0
  305. package/test/umd.bundle.hasEqual.more.test.js +68 -0
  306. package/test/umd.bundle.hasEqual.test.js +104 -0
  307. package/test/umd.bundle.logger-extra.test.js +48 -0
  308. package/test/umd.bundle.more-coverage-2.test.js +67 -0
  309. package/test/umd.bundle.pool.test.js +134 -0
  310. package/test/umd.bundle.test.js +265 -0
  311. package/test/utils.measure.test.js +49 -0
  312. package/test/utils.now.extra.test.js +30 -0
  313. package/test/utils.now.more.test.js +57 -0
  314. package/tsconfig.json +16 -0
  315. package/typedoc.json +25 -0
  316. package/types/helpers/constants.d.ts +49 -0
  317. package/types/helpers/jsdoc-types.d.ts +250 -0
  318. package/types/helpers/powerBackpressure.d.ts +40 -0
  319. package/types/helpers/powerBatch.d.ts +73 -0
  320. package/types/helpers/powerBuffer.d.ts +6 -0
  321. package/types/helpers/powerBulkhead.d.ts +78 -0
  322. package/types/helpers/powerCache.d.ts +613 -0
  323. package/types/helpers/powerChunking.d.ts +41 -0
  324. package/types/helpers/powerCircuit.d.ts +43 -0
  325. package/types/helpers/powerDeadline.d.ts +36 -0
  326. package/types/helpers/powerDefer.d.ts +47 -0
  327. package/types/helpers/powerEventBus.d.ts +108 -0
  328. package/types/helpers/powerHistogram.d.ts +57 -0
  329. package/types/helpers/powerLatch.d.ts +89 -0
  330. package/types/helpers/powerLogger.d.ts +139 -0
  331. package/types/helpers/powerObserver.d.ts +44 -0
  332. package/types/helpers/powerPermitGate.d.ts +68 -0
  333. package/types/helpers/powerPool.d.ts +555 -0
  334. package/types/helpers/powerQueue.d.ts +126 -0
  335. package/types/helpers/powerRateLimit.d.ts +90 -0
  336. package/types/helpers/powerRetry.d.ts +35 -0
  337. package/types/helpers/powerScheduler.d.ts +44 -0
  338. package/types/helpers/powerSemaphore.d.ts +44 -0
  339. package/types/helpers/powerSlidingWindow.d.ts +44 -0
  340. package/types/helpers/powerSubscriberSet.d.ts +78 -0
  341. package/types/helpers/powerTTLMap.d.ts +108 -0
  342. package/types/helpers/powerThrottle.d.ts +86 -0
  343. package/types/index.d.ts +26 -0
  344. package/types/utils/errors.d.ts +30 -0
  345. package/types/utils/now.d.ts +45 -0
  346. package/vite.config.js +31 -0
  347. package/vitest.config.js +17 -0
package/.eslintrc.cjs ADDED
@@ -0,0 +1,22 @@
1
+ module.exports = {
2
+ env: {
3
+ es2021: true,
4
+ node: true,
5
+ browser: true,
6
+ },
7
+ parserOptions: {
8
+ ecmaVersion: 2021,
9
+ sourceType: 'module',
10
+ },
11
+ extends: [
12
+ 'eslint:recommended',
13
+ 'plugin:prettier/recommended'
14
+ ],
15
+ rules: {
16
+ semi: ['error', 'always'],
17
+ quotes: ['error', 'single'],
18
+ 'no-unused-vars': ['warn'],
19
+ 'no-empty': 'off',
20
+ 'no-useless-catch': 'off',
21
+ },
22
+ };
package/.nojekyll ADDED
File without changes
package/.prettierrc ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "semi": true,
3
+ "singleQuote": true,
4
+ "trailingComma": "es5",
5
+ "printWidth": 100
6
+ }
@@ -0,0 +1,178 @@
1
+ # Contributing
2
+
3
+ Thanks for contributing to `performance-helpers`.
4
+
5
+ This project is a small, performance-focused JavaScript toolbox for Node.js and browser runtimes. Contributions should stay consistent with that goal: small APIs, predictable behavior, low overhead, and clear documentation.
6
+
7
+ Repository: <https://github.com/AbelVM/performance-helpers>
8
+
9
+ ## Prerequisites
10
+
11
+ - Node.js 16 or newer
12
+ - npm
13
+
14
+ Install dependencies:
15
+
16
+ ```bash
17
+ npm install
18
+ ```
19
+
20
+ ## Project layout
21
+
22
+ - `src/helpers/`: helper implementations
23
+ - `src/utils/`: small shared utilities
24
+ - `test/`: Vitest coverage for helpers and edge cases
25
+ - `guides/`: user-facing helper guides
26
+ - `bench/`: benchmark runners and benchmark docs
27
+ - `types/`: generated declaration output
28
+
29
+ ## Development workflow
30
+
31
+ 1. Make the smallest change that solves the problem.
32
+ 2. Keep public APIs stable unless the change explicitly requires API work.
33
+ 3. Add or update tests for behavior changes.
34
+ 4. Update the relevant guide or README entry when user-facing behavior changes.
35
+ 5. Run the relevant validation commands before opening a PR.
36
+
37
+ ## Useful commands
38
+
39
+ Run tests:
40
+
41
+ ```bash
42
+ npm run test
43
+ ```
44
+
45
+ Run linting:
46
+
47
+ ```bash
48
+ npm run lint
49
+ ```
50
+
51
+ Auto-fix lint issues:
52
+
53
+ ```bash
54
+ npm run lint:fix
55
+ ```
56
+
57
+ Format source and markdown:
58
+
59
+ ```bash
60
+ npm run format
61
+ ```
62
+
63
+ Generate declaration files:
64
+
65
+ ```bash
66
+ npm run types:generate
67
+ ```
68
+
69
+ Build the project:
70
+
71
+ ```bash
72
+ npm run build
73
+ ```
74
+
75
+ Generate docs:
76
+
77
+ ```bash
78
+ npm run docs
79
+ ```
80
+
81
+ Run benchmarks:
82
+
83
+ ```bash
84
+ npm run bench
85
+ ```
86
+
87
+ Run the full validation pipeline:
88
+
89
+ ```bash
90
+ npm run build:full
91
+ ```
92
+
93
+ ## Coding guidelines
94
+
95
+ - Prefer plain JavaScript and small abstractions over framework-style layering.
96
+ - Keep hot-path allocations and hidden work low.
97
+ - Avoid adding dependencies unless there is a clear, durable payoff.
98
+ - Preserve the existing naming style and file organization.
99
+ - Write examples and docs using realistic usage patterns, not placeholder pseudocode.
100
+ - When changing helper behavior, consider edge cases such as timeouts, cancellation, queue saturation, expiry, and cleanup.
101
+
102
+ ## Testing expectations
103
+
104
+ - Add focused tests near the affected helper area in `test/`.
105
+ - Cover both normal behavior and failure or edge cases.
106
+ - Prefer narrow, explicit tests over large multi-concern tests.
107
+ - If a helper has concurrency, timing, or retry behavior, test the boundary conditions.
108
+ - Keep the repository-wide coverage baseline green; use helper-specific work to raise weaker files toward Tier 1.
109
+
110
+ ## Tier 1 helper checklist
111
+
112
+ Use this checklist when promoting or maintaining a helper as Tier 1:
113
+
114
+ - The helper has a dedicated guide and a README entry.
115
+ - Public methods and constructor options have concise JSDoc with edge-case behavior spelled out.
116
+ - Behavior-changing work includes focused regression tests.
117
+ - The helper keeps per-file coverage at or above the repository targets during promotion, with branch coverage treated as mandatory.
118
+ - Known correctness issues are fixed before broadening the API.
119
+ - Performance-sensitive paths avoid avoidable allocations, duplicate clocks, and duplicated state machines.
120
+ - If the helper composes other helpers, shared substrate should be reused instead of reimplemented.
121
+
122
+ Helpers that cannot satisfy this bar without excessive complexity should stay advanced or internal until their scope is reduced.
123
+
124
+ Current exceptions to treat deliberately rather than mechanically:
125
+
126
+ - `PowerPool` is an advanced helper. Its scope is intentionally broader than most helpers here, so promotion work should focus on correctness, docs, and high-value edge cases instead of forcing it into the same maintenance profile as the smallest primitives.
127
+ - `PowerRateLimit` currently has an anomalous function-coverage number despite strong public-path coverage. Do not treat that metric alone as proof of missing behavior unless a concrete branch or regression is identified.
128
+ - For broad helpers, prefer documenting scope and trade-offs over adding low-value tests that only improve a report without increasing confidence.
129
+
130
+ ## Documentation expectations
131
+
132
+ Update documentation when any of the following changes:
133
+
134
+ - public API
135
+ - constructor options
136
+ - method semantics
137
+ - examples
138
+ - performance trade-offs
139
+ - recommended helper combinations
140
+
141
+ At minimum, check whether one of these files needs an update:
142
+
143
+ - `README.md`
144
+ - `guides/*.md`
145
+ - `guides/metaGuide.md`
146
+
147
+ ## Pull requests
148
+
149
+ A good pull request should include:
150
+
151
+ - a clear problem statement
152
+ - a concise summary of the change
153
+ - tests for behavior changes
154
+ - docs updates when user-facing behavior changed
155
+ - notes about benchmark impact when performance-sensitive code changed
156
+
157
+ If the change affects runtime cost, concurrency, or memory behavior, include benchmark numbers or at least a short explanation of the expected trade-off.
158
+
159
+ ## Scope guidance
160
+
161
+ Good contributions:
162
+
163
+ - bug fixes
164
+ - test improvements
165
+ - documentation clarifications
166
+ - performance improvements with evidence
167
+ - small, coherent helper enhancements
168
+
169
+ Higher-risk changes that need extra care:
170
+
171
+ - public API redesigns
172
+ - new dependencies
173
+ - behavior changes in core helpers like cache, pool, queue, retry, or rate limiting
174
+ - changes that make examples or guides drift from the actual implementation
175
+
176
+ ## Questions
177
+
178
+ If you are unsure whether a change fits the project, open an issue or draft PR with the intended API, behavior, and trade-offs before expanding the implementation.
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ # MIT License
2
+
3
+ **Copyright (c) 2026 Abel Vázquez Montoro**
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,194 @@
1
+ # performance-helpers
2
+
3
+ [![npm version](https://img.shields.io/npm/v/performance-helpers.svg)](https://www.npmjs.com/package/performance-helpers) [![npm downloads](https://img.shields.io/npm/dm/performance-helpers.svg)](https://www.npmjs.com/package/performance-helpers) [![GitHub stars](https://img.shields.io/github/stars/AbelVM/performance-helpers.svg)](https://github.com/AbelVM/performance-helpers/stargazers) [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE.md)
4
+
5
+ ![logo](assets/logo.png)
6
+
7
+ Highly tuned lightweight toolbox for high-performance Node/browser code: zero-copy buffer helpers for worker messaging, an LRU TTL cache with a memoizer, a fully-featured worker pool wrapper, a tiny runtime debug logger, and much more:
8
+
9
+ ## Caching
10
+
11
+ - [PowerCache: Caching (LRU + TTL + weight) and memoizing](guides/powerCache.md). An in-memory, memory-efficient LRU cache with TTL, weighted eviction and an optional reusable node pool.
12
+ - [PowerTTLMap: Map with per-key TTL](guides/powerTTLMap.md). Lightweight `Map`-like store where keys expire lazily on access.
13
+
14
+ ## Parallelizing
15
+
16
+ - [PowerPool: Worker pool](guides/powerPool.md). A small, dependency-free worker pool that wraps underlying Worker instances.
17
+ - [PowerChunker: Chunk + pool helper](guides/powerChunking.md). Convenience helper to chunk iterables and process items via a `PowerPool`.
18
+ - [PowerBulkhead: Partitioned executor](guides/powerBulkhead.md). Isolate noisy workloads into separate lanes so one hot partition cannot starve the rest.
19
+ - [PowerCircuit: Circuit breaker](guides/powerCircuit.md). Small circuit breaker to protect external services from cascading failures.
20
+ - [PowerRetry: Retry with backoff](guides/powerRetry.md). Helper for retrying flaky async operations with configurable backoff and jitter.
21
+ - [PowerDeadline: Timeout, retry budget, and cancellation](guides/powerDeadline.md). Wrap async work with per-attempt timeouts, overall deadlines, and retry policy.
22
+ - [PowerHistogram: Lock-free percentile estimator](guides/powerHistogram.md). Compact in-process histogram for latency telemetry and estimated percentiles.
23
+ - [PowerBackpressure: Producer-facing backpressure controller](guides/powerBackpressure.md). Gate producers with adaptive refill and bounded waiting.
24
+ - [PowerBatch: Microtask coalescing dispatcher](guides/powerBatch.md). Coalesce synchronous calls into compact batches for bulk operations.
25
+ - [PowerLatch: Counting barrier](guides/powerLatch.md). Simple barrier that resolves when a count reaches zero. Useful for coordinating out-of-band task completions.
26
+ - [PowerThrottle: A token-bucket limiter](guides/powerThrottle.md). A tiny rate limiter useful for pacing external work or cooperating with `PowerPool`. New: supports `reserve()`/`release()` for reservation-style workflows.
27
+ - [PowerRateLimit: Compose multiple limiters](guides/powerRateLimit.md). Combine `PowerThrottle`, `PowerSlidingWindow` and others; supports an `atomic` option to attempt atomic consumes across composed limiters.
28
+ - [PowerSlidingWindow: Sliding-window limiter](guides/powerSlidingWindow.md). A simple rolling-window limiter for quota-style rate limiting.
29
+ - [PowerQueue: O(1) ring-buffer queue](guides/powerQueue.md). A resizable, high-performance queue intended for use in `PowerPool` and other high-throughput scenarios.
30
+ - [PowerSemaphore: Async concurrency gate](guides/powerSemaphore.md). Lightweight semaphore for limiting concurrent I/O and fan-out workloads.
31
+ - [PowerEventBus: Typed micro event bus](guides/powerEventBus.md). Lightweight pub/sub for intra-process coordination between helpers.
32
+
33
+ ## Logging
34
+
35
+ - [PowerLogger: Gated logging](guides/powerLogger.md). Simple runtime debug gate and in-memory counters useful for lightweight instrumentation and tests.
36
+
37
+ ## Utils
38
+
39
+ - [PowerBuffer: Encode/decode JS objects to transferables for worker messaging](guides/powerBuffer.md). Lightweight helpers for encoding/decoding JSON to/from binary (Uint8Array / ArrayBuffer / Node Buffer).
40
+ - [PowerDefer: Deferred promise primitive](guides/powerDefer.md). Small utility that separates a `Promise` from its `resolve`/`reject` functions.
41
+ - [PowerPermitGate: Permit queue helper](guides/powerPermitGate.md). Low-level concurrency gate that manages permits and FIFO waiters for building semaphore or backpressure primitives.
42
+ - [PowerScheduler: Work coalescing scheduler](guides/powerScheduler.md). Lightweight scheduler for batching deferred work into a single microtask or macrotask flush.
43
+ - [PowerSubscriberSet: Shared listener registry](guides/powerSubscriberSet.md). Internal subscriber helper with optional weak references and once-listener support.
44
+ - [PowerObserver: Lightweight reactive value](guides/powerObserver.md). Tiny observable primitive for synchronous subscriptions to a single value.
45
+ - [Now utilities: high-resolution timers and measure helpers](guides/now.md) — `nowMs()`, `measureSync()`, `measureAsync()` and timing best-practices.
46
+ - [Errors utilities: recommended error shapes and patterns](guides/errors.md) — guidance for attaching `duration`, `correlationId` and structured diagnostics to errors and responses.
47
+
48
+ ## When to use what
49
+
50
+ Check the [Quick Guide](guides/metaGuide.md)
51
+
52
+ ## Quick start
53
+
54
+ Requirements: Node.js and npm.
55
+
56
+ Install dependencies:
57
+
58
+ ```bash
59
+ npm install
60
+ ```
61
+
62
+ Install the package from npm for direct use in your project:
63
+
64
+ ```bash
65
+ npm install --save performance-helpers
66
+ # or
67
+ yarn add performance-helpers
68
+ ```
69
+
70
+ Run tests:
71
+
72
+ ```bash
73
+ npm run test
74
+ ```
75
+
76
+ Run coverage (v8):
77
+
78
+ ```bash
79
+ npm run test:coverage
80
+ ```
81
+
82
+ ## Quality bar
83
+
84
+ Helpers intended to be Tier 1 in this repository should meet a consistent bar:
85
+
86
+ - dedicated guide plus README coverage
87
+ - concise JSDoc for public constructor options and methods
88
+ - focused regression tests for edge cases and failure paths
89
+ - repo-wide coverage stays above the Vitest thresholds, and Tier 1 promotion work raises the helper's own file coverage to the same bar
90
+ - no known open correctness bugs in the public contract
91
+
92
+ Helpers that remain larger or more experimental can stay as advanced helpers, but Tier 1 helpers should be predictable, narrow in scope, and cheap to maintain.
93
+
94
+ Current classification notes:
95
+
96
+ - `PowerPool` is an advanced helper by design. It has a broader surface area than the narrow Tier 1 primitives, so coverage and maintenance expectations should be interpreted with that scope in mind.
97
+ - `PowerRateLimit` is treated as a metric outlier for function coverage. Its public behavior and rollback paths are heavily covered; the remaining low function number is not currently considered a release blocker on its own.
98
+ - Promotion work should prioritize public correctness, narrow APIs, and edge-case coverage before chasing residual coverage misses in broad orchestration helpers.
99
+
100
+ Build (Vite):
101
+
102
+ ```bash
103
+ npm run build
104
+ ```
105
+
106
+ Generate docs (Typedoc):
107
+
108
+ ```bash
109
+ npm run docs
110
+ ```
111
+
112
+ ## Usage examples
113
+
114
+ Importing from the package entry (or directly from `src/helpers/*` during development):
115
+
116
+ ```javascript
117
+ import {
118
+ o2b,
119
+ o2u8,
120
+ u82o,
121
+ b2o,
122
+ PowerCache,
123
+ PowerMemoizer,
124
+ PowerTimedCache,
125
+ PowerPool,
126
+ PowerLogger,
127
+ PowerThrottle,
128
+ PowerSlidingWindow,
129
+ PowerRateLimit,
130
+ PowerQueue,
131
+ PowerSemaphore,
132
+ PowerDefer,
133
+ PowerTTLMap,
134
+ nowMs,
135
+ measureSync,
136
+ measureAsync,
137
+ PowerCircuit,
138
+ PowerRetry,
139
+ PowerDeadline,
140
+ PowerHistogram,
141
+ PowerBackpressure,
142
+ PowerBatch,
143
+ PowerBulkhead,
144
+ PowerLatch,
145
+ PowerObserver,
146
+ PowerEventBus,
147
+ } from 'performance-helpers';
148
+ ```
149
+
150
+ ## CDN usage
151
+
152
+ You can import the package directly from a CDN for quick demos. Example using unpkg (ES module support):
153
+
154
+ ```html
155
+ <script type="module">
156
+ import { PowerMemoizer } from 'https://unpkg.com/performance-helpers@latest?module';
157
+ const fetchUser = async (id) => fetch(`/users/${id}`).then((r) => r.json());
158
+ const pm = new PowerMemoizer(fetchUser);
159
+ console.log(await pm.run(1));
160
+ </script>
161
+ ```
162
+
163
+ Or using jsDelivr:
164
+
165
+ ```html
166
+ <script type="module">
167
+ import { PowerCache } from 'https://cdn.jsdelivr.net/npm/performance-helpers@latest/dist/index.js';
168
+ const cache = new PowerCache();
169
+ cache.set('a', 1);
170
+ console.log(cache.get('a'));
171
+ </script>
172
+ ```
173
+
174
+ UMD example (script tag):
175
+
176
+ ```html
177
+ <script src="https://unpkg.com/performance-helpers@latest/dist/performance-helpers.umd.js"></script>
178
+ <script>
179
+ // UMD builds attach a global. Use the global that your build exposes.
180
+ const lib = window.PerformanceHelpers;
181
+ const { PowerCache } = lib || {};
182
+ const cache = new PowerCache();
183
+ cache.set('a', 2);
184
+ console.log(cache.get('a'));
185
+ </script>
186
+ ```
187
+
188
+ ## API docs
189
+
190
+ Full API documentation [here](docs/README.md)
191
+
192
+ ## License
193
+
194
+ [MIT](LICENSE.md).
@@ -0,0 +1,4 @@
1
+ # Caching
2
+
3
+ - [PowerCache: Caching (LRU + TTL + weight) and memoizing](../guides/powerCache.md). An in-memory, memory-efficient LRU cache with TTL, weighted eviction and an optional reusable node pool.
4
+ - [PowerTTLMap: Map with per-key TTL](../guides/powerTTLMap.md). Lightweight `Map`-like store where keys expire lazily on access.
@@ -0,0 +1,18 @@
1
+ # Parallelizing
2
+
3
+ - [PowerPool: Worker pool](../guides/powerPool.md). A small, dependency-free worker pool that wraps underlying Worker instances.
4
+ - [PowerChunker: Chunk + pool helper](../guides/powerChunking.md). Convenience helper to chunk iterables and process items via a `PowerPool`.
5
+ - [PowerBulkhead: Partitioned executor](../guides/powerBulkhead.md). Isolate noisy workloads into separate lanes so one hot partition cannot starve the rest.
6
+ - [PowerCircuit: Circuit breaker](../guides/powerCircuit.md). Small circuit breaker to protect external services from cascading failures.
7
+ - [PowerRetry: Retry with backoff](../guides/powerRetry.md). Helper for retrying flaky async operations with configurable backoff and jitter.
8
+ - [PowerDeadline: Timeout, retry budget, and cancellation](../guides/powerDeadline.md). Wrap async work with per-attempt timeouts, overall deadlines, and retry policy.
9
+ - [PowerHistogram: Lock-free percentile estimator](../guides/powerHistogram.md). Compact in-process histogram for latency telemetry and estimated percentiles.
10
+ - [PowerBackpressure: Producer-facing backpressure controller](../guides/powerBackpressure.md). Gate producers with adaptive refill and bounded waiting.
11
+ - [PowerBatch: Microtask coalescing dispatcher](../guides/powerBatch.md). Coalesce synchronous calls into compact batches for bulk operations.
12
+ - [PowerLatch: Counting barrier](../guides/powerLatch.md). Simple barrier that resolves when a count reaches zero. Useful for coordinating out-of-band task completions.
13
+ - [PowerThrottle: A token-bucket limiter](guides/powerThrottle.md). A tiny rate limiter useful for pacing external work or cooperating with `PowerPool`. New: supports `reserve()`/`release()` for reservation-style workflows.
14
+ - [PowerRateLimit: Compose multiple limiters](guides/powerRateLimit.md). Combine `PowerThrottle`, `PowerSlidingWindow` and others; supports an `atomic` option to attempt atomic consumes across composed limiters.
15
+ - [PowerSlidingWindow: Sliding-window limiter](../guides/powerSlidingWindow.md). A simple rolling-window limiter for quota-style rate limiting.
16
+ - [PowerQueue: O(1) ring-buffer queue](../guides/powerQueue.md). A resizable, high-performance queue intended for use in `PowerPool` and other high-throughput scenarios.
17
+ - [PowerSemaphore: Async concurrency gate](../guides/powerSemaphore.md). Lightweight semaphore for limiting concurrent I/O and fan-out workloads.
18
+ - [PowerEventBus: Typed micro event bus](../guides/powerEventBus.md). Lightweight pub/sub for intra-process coordination between helpers.
@@ -0,0 +1,3 @@
1
+ # Logging
2
+
3
+ - [PowerLogger: Gated logging](../guides/powerLogger.md). Simple runtime debug gate and in-memory counters useful for lightweight instrumentation and tests.
package/assets/404.md ADDED
@@ -0,0 +1,3 @@
1
+ # Not found
2
+
3
+ Go back to [home](../README.md)
@@ -0,0 +1,10 @@
1
+ # Utils
2
+
3
+ - [PowerBuffer: Encode/decode JS objects to transferables for worker messaging](../guides/powerBuffer.md). Lightweight helpers for encoding/decoding JSON to/from binary (Uint8Array / ArrayBuffer / Node Buffer).
4
+ - [PowerDefer: Deferred promise primitive](../guides/powerDefer.md). Small utility that separates a `Promise` from its `resolve`/`reject` functions.
5
+ - [PowerPermitGate: Permit queue helper](../guides/powerPermitGate.md). Low-level concurrency gate that manages permits and FIFO waiters for building semaphore or backpressure primitives.
6
+ - [PowerScheduler: Work coalescing scheduler](../guides/powerScheduler.md). Lightweight scheduler for batching deferred work into a single microtask or macrotask flush.
7
+ - [PowerSubscriberSet: Shared listener registry](../guides/powerSubscriberSet.md). Internal subscriber helper with optional weak references and once-listener support.
8
+ - [PowerObserver: Lightweight reactive value](../guides/powerObserver.md). Tiny observable primitive for synchronous subscriptions to a single value.
9
+ - [Now utilities: high-resolution timers and measure helpers](../guides/now.md) — `nowMs()`, `measureSync()`, `measureAsync()` and timing best-practices.
10
+ - [Errors utilities: recommended error shapes and patterns](../guides/errors.md) — guidance for attaching `duration`, `correlationId` and structured diagnostics to errors and responses
Binary file
@@ -0,0 +1,10 @@
1
+ [home](README.md)
2
+ [Quick Guide](guides/metaGuide.md)
3
+ [Caching](assets/1_Caching.md)
4
+ [Parallelizing](assets/2_Parallelizing.md)
5
+ [Logging](assets/3_Logging.md)
6
+ [Utils](assets/4_Utils.md)
7
+ [API](docs/README.md)
8
+ [Benchmark](bench/results.md)
9
+ [Contributing](CONTRIBUTING.md)
10
+ [License](LICENSE.md)
@@ -0,0 +1,97 @@
1
+ # Benchmarks
2
+
3
+ Lightweight benchmarking helpers for `PowerPool` and `PowerCache`.
4
+
5
+ This folder contains a small harness (`bench/run.js`) that measures:
6
+
7
+ - single-threaded CPU-bound compute (baseline) with **p50/p95/p99** per-task latency
8
+ - multi-worker `PowerPool` performance across pool sizes with **speedup vs single-threaded**
9
+ - a simple `PowerCache` hit/miss benchmark
10
+ - `PowerPool + PowerCache` optimized cache reuse patterns
11
+ - `PowerPool` autoscaling performance
12
+ - `PowerMemoizer` memoization overhead with duplicate keys
13
+ - multiple real-world load profiles: `0%`, `25%`, `50%`, `75%`, and `100%` variable load
14
+ - additional realistic scenario benchmarks, including:
15
+ - `Burstiness`: sudden bursts of work followed by short quiet periods
16
+ - `Mixed task sizes`: alternating light and heavy work items to mimic uneven request costs
17
+ - `Ramp traffic`: gradual ramp-up and ramp-down of task submission rates
18
+ - `Variable payload sizes`: payloads with different serialized sizes to exercise data movement
19
+ - `I/O bound`: tasks that include small async wait periods to simulate I/O latency
20
+ - `Thundering herd`: many tasks contending for the same cache key at once
21
+ - `Cache hit-ratio sweeps`: low/medium/high reuse ratios for cache-backed work
22
+ - `Cache warmup behavior`: cold vs warm cache performance for repeated workloads
23
+ - `Cache eviction under pressure`: tight maxEntries (20% of unique keys) measuring LRU overhead
24
+ - `Serial vs concurrent getOrSetAsync`: in-flight deduplication benefit quantified
25
+ - **helper micro-benchmarks** for primitives not covered by the pool harness:
26
+ - `PowerRateLimit`: tryConsume throughput under rate (all pass) and over rate (~50% rejected)
27
+ - `PowerCircuit`: `call()` overhead in closed (happy path) vs open (fast-fail) state
28
+ - `PowerRetry`: `run()` overhead with 0 retries and 1 retry (baseDelay=0)
29
+ - `PowerSemaphore`: serial (limit=1) and concurrent (limit=8) permit acquisition
30
+ - `PowerBulkhead`: single partition vs 2-partition critical/background isolation
31
+ - `PowerBatch`: individual dispatch (maxSize=1) vs coalesced dispatch
32
+ - `PowerBackpressure`: acquire/release with no pressure and with capacity=100
33
+ - `PowerTTLMap`: set/get throughput with long TTL (no eviction) and short TTL (1 ms, high churn)
34
+ - `PowerEventBus`: `emit` fan-out throughput at 1 / 10 / 50 / 100 subscribers
35
+ - `PowerDeadline`: success path overhead and abort-path cost when task exceeds deadline
36
+ - `PowerSlidingWindow`: `tryConsume` throughput under capacity and at capacity
37
+ - `PowerQueue`: bulk push+shift and interleaved (ring-buffer steady state)
38
+ - **historical delta comparison**: on each run, results are compared against the previous `results.json` and regressions/improvements > 5% are highlighted in the markdown
39
+
40
+ Quick usage
41
+
42
+ ```bash
43
+ # Run the full benchmark suite (profiles + cache + helpers)
44
+ npm run bench
45
+
46
+ # Run only the profile-based worker-pool benchmarks (across variable load mixes)
47
+ npm run bench:pool
48
+
49
+ # Run only the cache workload
50
+ npm run bench:cache
51
+
52
+ # Run the profile-based pool benchmark directly
53
+ node bench/run.js profiles
54
+
55
+ # Run only the realistic scenario benchmarks
56
+ node bench/run.js scenarios
57
+
58
+ # Run only the helper micro-benchmarks
59
+ node bench/run.js helpers
60
+
61
+ # Alias for the same profile benchmark flow
62
+ node bench/run.js variable
63
+ ```
64
+
65
+ Environment variables (defaults shown)
66
+
67
+ - `BENCH_TASKS` (default: `1000`) — number of tasks submitted to the pool (or keys for cache benchmark)
68
+ - `BENCH_ITERS` (default: `1000000`) — work per task (higher = heavier per-task CPU)
69
+ - `BENCH_POOLS` (default: `1,2,4,8`) — comma-separated pool sizes when running pool benchmarks
70
+ - `BENCH_POOL_TIMEOUT` (default: `0`) — ms timeout for each `PowerPool` run; set to `0` to disable timeout and let the pool run to completion
71
+ - `BENCH_CACHE_DUPLICATE_KEYS` (default: `10`) — unique key count for cache getOrSetAsync duplicate-key benchmark
72
+ - `BENCH_MEMOIZER_DUPLICATE_KEYS` (default: `10`) — unique key count for PowerMemoizer repeated-call benchmark
73
+ - `BENCH_AUTOSCALE_CACHE_KEYS` (default: `10`) — unique key count for autoscale + cache duplicate-key benchmark
74
+ - `BENCH_POOL_RUNS` (default: `3`) — repeat each pool/scenario variant N times and report the result closest to the median wall-clock time; set to `3` for more stable pool numbers at the cost of a ~3× longer run
75
+ - `BENCH_RUNS` (default: `5`) — repeat each helper micro-benchmark N times and report the median; reduces measurement noise from OS jitter and JIT warm-up variance
76
+ - `BENCH_HELPER_OPS` (default: `100000`) — operation count for each helper micro-benchmark variant
77
+
78
+ Tips and notes
79
+
80
+ - Start with small values during iteration: `BENCH_TASKS=2 BENCH_ITERS=10000` to validate changes quickly
81
+ - Use `BENCH_POOL_TIMEOUT=0` when you expect long runs and don't want the harness to fall back to the plain `worker_threads` implementation
82
+ - Use `BENCH_POOL_RUNS=3` for more stable pool benchmark numbers on a noisy machine (runs each pool variant 3 times, reports median)
83
+ - Use `BENCH_RUNS=7` for even more stable helper micro-benchmark numbers on a noisy machine
84
+ - Use `BENCH_HELPER_OPS=10000` to run a quick smoke test of all helpers
85
+ - The harness writes human-readable results to `bench/results.md` and writes a machine-readable copy to `results.json` at the repository root; the markdown contains a link to that file
86
+
87
+ Example quick smoke run
88
+
89
+ ```bash
90
+ BENCH_TASKS=2 BENCH_ITERS=10000 BENCH_POOLS=1 BENCH_POOL_TIMEOUT=0 BENCH_HELPER_OPS=1000 node bench/run.js pool
91
+ ```
92
+
93
+ Reproducibility
94
+
95
+ - Run the same `BENCH_TASKS`, `BENCH_ITERS` and `BENCH_POOLS` across machines to compare relative performance
96
+ - Benchmark results are noisy on shared machines; run multiple times and take median/mean as appropriate
97
+ - The `Δ prev` column in the markdown shows changes relative to the previous `results.json` on disk — commit `results.json` to track regressions over time