yield-result 0.1.5 → 0.1.6

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 +12 -18
  2. package/package.json +2 -3
package/README.md CHANGED
@@ -65,30 +65,24 @@ npm install yield-result
65
65
 
66
66
  ---
67
67
 
68
- ## 🏎️ Performance Benchmarks
68
+ ## 🔬 Architectural Analysis & V8 Engine Optimization
69
69
 
70
- Benchmarked using `vitest bench` (powered by `tinybench`) on Node.js:
70
+ ### Why We Do Not Use `throw` Internally for Flow Control
71
71
 
72
- ### 🔴 Unhappy Path (Error Triggered)
72
+ While libraries like `neverthrow` are fantastic, their generator-based flow control (`safeTry`) relies on calling `.safeUnwrap()`, which **throws native exceptions internally** to unwind the generator stack back to a `catch` block.
73
73
 
74
- When errors actually occur during domain execution:
74
+ In JavaScript V8 engines (Node.js, Chrome), throwing exceptions forces the engine to:
75
+ 1. Pause the execution loop.
76
+ 2. Capture full call stack frames.
77
+ 3. Deoptimize JIT compiler loops.
75
78
 
76
- | Implementation | Operations / sec | Benchmark Summary |
77
- | :--- | :---: | :--- |
78
- | **`yield-result` (`safe.sync`)** | **`207,485 ops/sec`** | ⚡ **3.55x FASTER than native try/catch** |
79
- | **Native `try/catch` with `throw`** | **`58,515 ops/sec`** | 🐢 3.55x slower |
79
+ **`yield-result` takes a zero-exception approach**:
80
+ Our generator runners (`safe.sync` / `safe.async` / `Result.gen`) rely **exclusively on ECMAScript native iteration protocols (`Symbol.iterator`)**.
80
81
 
81
- > 🏆 **Why is `yield-result` 3.55x faster on errors?**
82
- > Native `throw new Error()` forces JavaScript V8 engines to pause execution, capture call stack frames, allocate Error objects, and deoptimize JIT loops. In `yield-result`, returning an `Err` is just returning a plain object without unwinding stack frames.
82
+ - **`Ok<T>`** returns its value directly in 0 suspension steps.
83
+ - **`Err<E>`** yields the `Err` object once to the runner, which immediately triggers `gen.return()` and early-returns the `Err` value.
83
84
 
84
- ### 🟢 Happy Path (Success Flow)
85
-
86
- | Implementation | Operations / sec | Average Latency |
87
- | :--- | :---: | :---: |
88
- | **Native `try/catch` (no throw)** | `11,372,962 ops/sec` | `0.0001 ms` |
89
- | **`yield-result` (`safe.sync`)** | `231,068 ops/sec` | `0.0043 ms` |
90
-
91
- *Over 230,000 complete domain pipelines evaluated per second on a single thread—zero impact on network or database latencies.*
85
+ By avoiding internal `throw` statements entirely, `yield-result` keeps your execution pipeline 100% JIT-optimizable by the V8 engine under both happy and unhappy path conditions.
92
86
 
93
87
  ---
94
88
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yield-result",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "Rust-style ? operator for TypeScript using generators (yield*). Zero dependencies, type-safe error handling.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -47,9 +47,8 @@
47
47
  ],
48
48
  "license": "MIT",
49
49
  "devDependencies": {
50
+ "neverthrow": "^8.2.0",
50
51
  "typescript": "^5.5.4",
51
52
  "vitest": "^2.0.5"
52
53
  }
53
54
  }
54
-
55
-