@the-w1zard/singularity 1.0.12 → 1.0.13

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 (2) hide show
  1. package/README.md +215 -0
  2. package/package.json +3 -1
package/README.md CHANGED
@@ -3323,8 +3323,149 @@ Average: 11.36 M ops/sec
3323
3323
  ---------------------------------------------------------
3324
3324
  ```
3325
3325
 
3326
+ After performance update
3327
+ ```txt
3328
+ ------------ RAVEN.store.get ---------------
3329
+ Peak (Best Batch): 259.34 M ops/sec
3330
+ Average: 105.75 M ops/sec
3331
+ ---------------------------------------------------------
3332
+ ------------ RAVEN.store.has ---------------
3333
+ Peak (Best Batch): 251.70 M ops/sec
3334
+ Average: 25.86 M ops/sec
3335
+ ---------------------------------------------------------
3336
+ ------------ RAVEN.store.set ---------------
3337
+ Peak (Best Batch): 64.93 M ops/sec
3338
+ Average: 33.37 M ops/sec
3339
+ ---------------------------------------------------------
3340
+ ------------ RAVEN.store.set.functional ---------------
3341
+ Peak (Best Batch): 39.16 M ops/sec
3342
+ Average: 26.11 M ops/sec
3343
+ ---------------------------------------------------------
3344
+ ------------ RAVEN.store.get.set ---------------
3345
+ Peak (Best Batch): 54.02 M ops/sec
3346
+ Average: 48.20 M ops/sec
3347
+ ---------------------------------------------------------
3348
+ ------------ RAVEN.store.entries ---------------
3349
+ Peak (Best Batch): 7.51 M ops/sec
3350
+ Average: 6.62 M ops/sec
3351
+ ---------------------------------------------------------
3352
+ ------------ RAVEN.store.subscribe ---------------
3353
+ Peak (Best Batch): 2.55 M ops/sec
3354
+ Average: 2.32 M ops/sec
3355
+ ---------------------------------------------------------
3356
+ ------------ RAVEN.store.persist.get ---------------
3357
+ Peak (Best Batch): 59.26 M ops/sec
3358
+ Average: 48.68 M ops/sec
3359
+ ---------------------------------------------------------
3360
+ ------------ RAVEN.store.persist.has ---------------
3361
+ Peak (Best Batch): 72.35 M ops/sec
3362
+ Average: 64.40 M ops/sec
3363
+ ---------------------------------------------------------
3364
+ ------------ RAVEN.store.persist.set ---------------
3365
+ Peak (Best Batch): 50.32 M ops/sec
3366
+ Average: 47.28 M ops/sec
3367
+ ---------------------------------------------------------
3368
+ ------------ RAVEN.state.get ---------------
3369
+ Peak (Best Batch): 53.19 M ops/sec
3370
+ Average: 33.23 M ops/sec
3371
+ ---------------------------------------------------------
3372
+ ------------ RAVEN.state.getHot ---------------
3373
+ Peak (Best Batch): 145.39 M ops/sec
3374
+ Average: 107.64 M ops/sec
3375
+ ---------------------------------------------------------
3376
+ ------------ RAVEN.state.set ---------------
3377
+ Peak (Best Batch): 33.32 M ops/sec
3378
+ Average: 18.04 M ops/sec
3379
+ ---------------------------------------------------------
3380
+ ------------ RAVEN.state.get.set ---------------
3381
+ Peak (Best Batch): 80.10 M ops/sec
3382
+ Average: 61.39 M ops/sec
3383
+ ---------------------------------------------------------
3384
+ ------------ RAVEN.state.getAll ---------------
3385
+ Peak (Best Batch): 6.68 M ops/sec
3386
+ Average: 5.65 M ops/sec
3387
+ ---------------------------------------------------------
3388
+ ------------ RAVEN.state.getByPrefix ---------------
3389
+ Peak (Best Batch): 4.68 M ops/sec
3390
+ Average: 4.17 M ops/sec
3391
+ ---------------------------------------------------------
3392
+ ------------ RAVEN.state.subscribe ---------------
3393
+ Peak (Best Batch): 2.90 M ops/sec
3394
+ Average: 2.64 M ops/sec
3395
+ ---------------------------------------------------------
3396
+ ------------ RAVEN.state.notify ---------------
3397
+ Peak (Best Batch): 1.18 M ops/sec
3398
+ Average: 0.96 M ops/sec
3399
+ ---------------------------------------------------------
3400
+ ------------ RAVEN.darkState.get ---------------
3401
+ Peak (Best Batch): 2.57 M ops/sec
3402
+ Average: 2.08 M ops/sec
3403
+ ---------------------------------------------------------
3404
+ ------------ RAVEN.darkState.set ---------------
3405
+ Peak (Best Batch): 15.56 M ops/sec
3406
+ Average: 14.42 M ops/sec
3407
+ ---------------------------------------------------------
3408
+ ------------ RAVEN.darkState.get.set ---------------
3409
+ Peak (Best Batch): 2.19 M ops/sec
3410
+ Average: 1.80 M ops/sec
3411
+ ---------------------------------------------------------
3412
+ ------------ RAVEN.darkState.selector.get ---------------
3413
+ Peak (Best Batch): 2.46 M ops/sec
3414
+ Average: 1.77 M ops/sec
3415
+ ---------------------------------------------------------
3416
+ ------------ RAVEN.darkState.selector.set ---------------
3417
+ Peak (Best Batch): 8.58 M ops/sec
3418
+ Average: 8.18 M ops/sec
3419
+ ---------------------------------------------------------
3420
+ ------------ RAVEN.darkState.derived.get ---------------
3421
+ Peak (Best Batch): 2.47 M ops/sec
3422
+ Average: 1.91 M ops/sec
3423
+ ---------------------------------------------------------
3424
+ ------------ RAVEN.darkState.derived.set ---------------
3425
+ Peak (Best Batch): 12.58 M ops/sec
3426
+ Average: 12.15 M ops/sec
3427
+ ---------------------------------------------------------
3428
+ ```
3429
+
3326
3430
  </details>
3327
3431
 
3432
+ > [!NOTE] BUILDERS LOG #16
3433
+ >
3434
+ > TLDR: design bench so that the test runs in the sub one sec time window or when 11 secs has elapsed. This rule would remove all variables concerning v8.
3435
+ >
3436
+ > The discrepency in numbers... man, am I fucking so happy that... it dawned on me when it did hahaha, or else I would literally be here for days trying to figure this out...
3437
+ >
3438
+ > SOOOOO... couple of things are working against us, thankfully I only wasted like 20 mins on this, but since we are now benching against the real live implementation in place of a set up bench and harness it changes how we hit v8 than we did previously.
3439
+ >
3440
+ > The implementation has a ready boolean to signify once everything has been initalised, that is part of the problem.
3441
+ >
3442
+ > The second problem was where exactly during v8s execution window, were we hitting exactly. For those of you that dont know v8s execution window starts with the largest burst of performance fitting within a sub 1 second window. Which is how 99% of all users us v8, which is why this exists. If v8 continues to run, it sees a massive dip, obviously, following the burst up till around the 5-6 second mark. When it expereiences another dip, due to handing off the process to v8s turbo. From here... it takes till the around the 10 sec mark to finally start hitting v8s turbo when it has fully initialized.
3443
+ >
3444
+ > Basically... the hot paths we were testing fucking... just hit it at all the wrong times as you can see here:
3445
+ > ```txt
3446
+ > ------------ RAVEN.state.getHot2 ---------------
3447
+ > Peak (Best Batch): 1453.49 M ops/sec
3448
+ > Average: 587.23 M ops/sec
3449
+ > ---------------------------------------------------------
3450
+ > ------------ RAVEN.state.getHot ---------------
3451
+ > Peak (Best Batch): 376.36 M ops/sec
3452
+ > Average: 206.64 M ops/sec
3453
+ > ---------------------------------------------------------
3454
+ > ```
3455
+ > Prior to this run, both hot paths were only hitting 100 mill lol... as you can see here, hot 2 is hitting the burst on its way down since it is only getting 1453 here, when it should be getting almost 1700. getHot, previousl runs at 100, now almost at the very end of the burst is at 375... sooo...
3456
+ >
3457
+ > In order to have complete control and give each test the same variables... we need to design the tests differently, that way each test atleast has the same parameters to run that way we aren't accidently changing them from test to test and not making us wonder about life on why one test is so much slower then the next. When in reality, it literally has nothing to do with the code, the bench or the harness... but in fact, it was v8 all along.
3458
+ >
3459
+ > But let me be clear. We are NOT designing your average bench mark of warm up phase, fucking 5+ seconds of other bullshit and then finally start testing for another 10 secs or whatever stupid and dumb processs they designed. THAT IS NOT HOW THE REAL WORLD USES V8, but instead benchmarkers, for whatever reason, bench against a made up and unreal synthetic test. The numbers do not translate to the real world in any form, but maybe sub 1% of use cases.
3460
+ >
3461
+ > There is a reason why v8 sub 1 sec performance... bursts the way it does. Since users only hit either the sub 1 burst, or when turbo has already flattened.
3462
+ >
3463
+ > The next time you create a test, keep that in mind. Because you may not even be hitting v8 at the exact timing you should be.
3464
+ >
3465
+ > If you do not beleive a fucking word of this... that's ok, go to the message queues repo... download the main test, and run vader, rule of 2, and raven and these three disruptors will give you an exact look into how v8s execution process actually runs in real time. And you can hit it as many times as you want to witness it.
3466
+ >
3467
+ > I would suggest keeping the tests to sub 20secs because at the 26 sec mark, you will heat soak the core and performance will drop based on your thermal situation. To run these tests, there is literally 0 configuration, just run 'bun run test.ts' since buns performance is much higher than nodes, and run the non-bare metal test. As the bare metal test does not log the results per second, but instead once when the test ends.
3468
+ >
3328
3469
 
3329
3470
  <details style="font-size: 14.5px;"><summary><strong><span style="font-size: 16px; font-family: monospace">[THE DARK SIDE: USE STATE]</span> </strong></summary>
3330
3471
 
@@ -3438,3 +3579,77 @@ Average: 11.36 M ops/sec
3438
3579
 
3439
3580
  </details>
3440
3581
 
3582
+ > [!NOTE] BUILDERS LOG #16
3583
+ >
3584
+ > I'm adding some final touches on the message queue and its adapters and an idea just came to me... along with a question... why do we always just create... a signle sub... when in reality there are in fact 2 subs, there is the one that devs usualy and almost 100% use which is the sub and unsub version, where you create the sub at the call site but also immediatly unsub the sub as soon as the first message comes in....
3585
+ >
3586
+ > Then theres the second kind, the kind that you do not want to unsub, the long standing version and in fact want it to stay open...
3587
+ >
3588
+ > It is super late in the game to change the api, but this would be adding to it in a way that won't disrupt the current paths, where they will stay the way they are as it already exposes the unsub version, and we simply just add the new one beside it.
3589
+ >
3590
+ ```tsx
3591
+ public sub = (() => {
3592
+ const fn = (handler: A, k: S, s: S = '_globalThis', m: S = this.m, r: S = this.r, c: c_type = "globalThis" ): () => V => {
3593
+ let unsub: () => V = () => {};
3594
+ const once_handler: A = (p: U) => {unsub();handler(p);};
3595
+ unsub = this.sub_infinity(once_handler, k, s, m, r, c);
3596
+ return unsub;
3597
+ };
3598
+
3599
+ public sub_infinity = (() => {
3600
+ const fn = (handler: A, k: S, s: S = '_globalThis', m: S = this.m, r: S = this.r, c: c_type = "globalThis"): () => V => {
3601
+ // CHANNEL LEVEL
3602
+ const channelSet = (mesh.getR(r, c)[r] ??= new Set<A>()) as Set<A>;
3603
+ channelSet.add(handler);
3604
+
3605
+ // SUB_CHANNEL LEVEL
3606
+ const subMap = mesh.getM(m, r, c);
3607
+ const subSet = (subMap[r] ??= new Set<A>()) as Set<A>;
3608
+ subSet.add(handler);
3609
+
3610
+ // TRIP_CHANNEL LEVEL
3611
+ const tripMap = mesh.getS(s, m, r, c);
3612
+ const tripSet = (tripMap[m] ??= new Set<A>()) as Set<A>;
3613
+ tripSet.add(handler);
3614
+
3615
+ // QUAD_CHANNEL LEVEL
3616
+ const quadMap = (tripMap[k] ??= Object.create(null)) as Record<S, Set<A>>;
3617
+ const quadSet = (quadMap[s] ??= new Set<A>()) as Set<A>;
3618
+ quadSet.add(handler);
3619
+
3620
+ return () => {
3621
+ // QUAD_CHANNEL
3622
+ quadSet.delete(handler);
3623
+ if (!quadSet.size) delete quadMap[s];
3624
+ if (!Object.keys(quadMap).length) delete tripMap[k];
3625
+
3626
+ // TRIP_CHANNEL
3627
+ tripSet.delete(handler);
3628
+ if (!tripSet.size) delete tripMap[m];
3629
+
3630
+ // SUB_CHANNEL
3631
+ subSet.delete(handler);
3632
+ if (!subSet.size) delete subMap[r];
3633
+
3634
+ // CHANNEL
3635
+ channelSet.delete(handler);
3636
+ if (!channelSet.size) delete mesh.getR(r, c)[r];
3637
+
3638
+ // Remove empty hierarchy nodes
3639
+ if (!Object.keys(subMap).length) { delete mesh.getR(c, r)[m]; }
3640
+ if (!Object.keys(tripMap).length) { delete mesh.getR(c, r)[m]; }
3641
+ };
3642
+ };
3643
+
3644
+ return fn;
3645
+ })();
3646
+ ```
3647
+
3648
+
3649
+
3650
+
3651
+
3652
+ > [!NOTE] PERFORMANCE NOTES
3653
+ >
3654
+ > - replace all maps with objs, arrays even better if you have the use case for them but arrays aren't the best for real world app use cases
3655
+ > - nesting fns in iiffes seems to experience a drop in total ops, from the results I have experienced. I still do this for erverything but hot paths due to increases ergo
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@the-w1zard/singularity",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "exports": {
@@ -40,6 +40,7 @@
40
40
  "@the-w1zard/dx": "^1.0.46",
41
41
  "@the-w1zard/hlc": "^1.0.1",
42
42
  "@the-w1zard/resolvers": "^1.0.3",
43
+ "@the-w1zard/solutions": "^1.0.6",
43
44
  "@the-w1zard/store": "^1.0.9",
44
45
  "@the-w1zard/the-registry": "^1.0.21",
45
46
  "@typescript-eslint/typescript-estree": "^8.73.0",
@@ -51,6 +52,7 @@
51
52
  "imports": {
52
53
  "#hlc": "@the-w1zard/hlc",
53
54
  "#dx": "@the-w1zard/dx",
55
+ "#solutions": "@the-w1zard/solutions",
54
56
  "#sauron": "@the-w1zard/the-cloud",
55
57
  "#the-cloud": "@the-w1zard/the-cloud",
56
58
  "#tc": "@the-w1zard/the-cloud",