barejs 0.1.26 โ†’ 0.1.27

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 +53 -80
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,24 +1,34 @@
1
+ This version of the README integrates the **`bun create`** workflow and the **Hybrid Handler** support we just finalized. It emphasizes that users can now skip manual setup entirely by using the CLI.
2
+
3
+ ---
4
+
1
5
  # ๐Ÿš€ BareJS
2
6
 
3
- BareJS is an ultra-high-performance web engine built on the **Bun** runtime, specifically architected for minimalism and the lowest possible latency. It represents the pinnacle of **Mechanical Sympathy**, ensuring that every line of software execution aligns perfectly with how modern CPUs process data.
7
+ BareJS is an ultra-high-performance web engine built on the **Bun** runtime, specifically architected for minimalism and the lowest possible latency. It represents the pinnacle of **Mechanical Sympathy**, ensuring software execution aligns perfectly with modern CPU data processing.
4
8
 
5
9
  <p align="left">
6
- <a href="[https://github.com/xarhang/bareJS/actions](https://github.com/xarhang/bareJS/actions)">
7
- <img src="[https://github.com/xarhang/bareJS/actions/workflows/bench.yml/badge.svg](https://github.com/xarhang/bareJS/actions/workflows/bench.yml/badge.svg)" alt="Performance Benchmark">
8
- </a>
9
- <a href="[https://xarhang.github.io/bareJS/dev/benchmarks/](https://xarhang.github.io/bareJS/dev/benchmarks/)">
10
- <img src="[https://img.shields.io/badge/Performance-Dashboard-blueviolet?style=flat-square&logo=speedtest](https://img.shields.io/badge/Performance-Dashboard-blueviolet?style=flat-square&logo=speedtest)" alt="Performance Dashboard">
11
- </a>
12
- <a href="[https://bun.sh](https://bun.sh)">
13
- <img src="[https://img.shields.io/badge/Bun-%3E%3D1.0.0-black?style=flat-square&logo=bun](https://img.shields.io/badge/Bun-%3E%3D1.0.0-black?style=flat-square&logo=bun)" alt="Bun Version">
14
- </a>
10
+ <a href="https://github.com/xarhang/bareJS/tags">
11
+ <img src="https://img.shields.io/github/v/tag/xarhang/bareJS?style=flat-square&logo=github&label=github&color=black" alt="GitHub Tag">
12
+ </a>
13
+ <a href="https://www.npmjs.com/package/barejs">
14
+ <img src="https://img.shields.io/npm/v/barejs?style=flat-square&logo=npm&color=CB3837" alt="NPM Version">
15
+ </a>
16
+ <a href="https://github.com/xarhang/bareJS/actions/workflows/bench.yml">
17
+ <img src="https://github.com/xarhang/bareJS/actions/workflows/bench.yml/badge.svg" alt="Performance Benchmark">
18
+ </a>
19
+ <a href="https://xarhang.github.io/bareJS/dev/benchmarks/">
20
+ <img src="https://img.shields.io/badge/Performance-Dashboard-blueviolet?style=flat-square&logo=speedtest" alt="Performance Dashboard">
21
+ </a>
22
+ <a href="https://bun.sh">
23
+ <img src="https://img.shields.io/badge/Bun-%3E%3D1.0.0-black?style=flat-square&logo=bun" alt="Bun Version">
24
+ </a>
15
25
  </p>
16
26
 
17
27
  ---
18
28
 
19
29
  ## ๐Ÿ“Š Performance Benchmarks: Breaking the Nanosecond Barrier
20
30
 
21
- BareJS is designed to be the definitive baseline for speed in the JavaScript ecosystem. By ruthlessly eliminating common framework overhead, we consistently achieve sub-microsecond latency.
31
+ BareJS is the definitive baseline for speed in the JavaScript ecosystem. By ruthlessly eliminating common framework overhead, we consistently achieve sub-microsecond latency.
22
32
 
23
33
  ### ๐Ÿ“ˆ Global Latency Comparison (Lower is Better)
24
34
  <!-- MARKER: PERFORMANCE_TABLE_START -->
@@ -29,110 +39,72 @@ BareJS is designed to be the definitive baseline for speed in the JavaScript eco
29
39
  | Elysia | 2.26 ยตs | 4.19x slower |
30
40
  | Hono | 4.02 ยตs | 7.46x slower |
31
41
 
32
- > Last Updated: Tue, 06 Jan 2026 19:23:27 GMT
42
+ > Last Updated: Tue, 07 Jan 2026 14:19:23:27 GMT
33
43
 
34
44
  <!-- MARKER: PERFORMANCE_TABLE_END -->
35
45
 
36
46
  <!-- NOTE: The table above is automatically updated via scripts/update-readme.ts -->
37
47
 
48
+
49
+ ## ๐Ÿ› ๏ธ Rapid Scaffolding (Recommended)
50
+
51
+ The fastest way to initialize a production-ready environment is via the official **`bun create`** command. This scaffolds a pre-configured project with optimized `tsconfig.json` and production build scripts.
52
+
53
+ ```bash
54
+ bun create barejs my-app
55
+ cd my-app
56
+ bun dev
57
+
58
+ ```
59
+
38
60
  ---
39
61
 
40
62
  ## ๐Ÿ› Architectural Engineering Deep-Dive
41
63
 
42
- Why is BareJS significantly faster than established frameworks? The answer lies in three core engineering pillars.
43
-
44
64
  ### 1. Zero-Allocation Circular Context Pool
45
65
 
46
- Traditional frameworks create a new Request or Context object for every single incoming hit, triggering constant Garbage Collector (GC) activity and unpredictable latency spikes.
47
-
48
- * **Pre-allocation**: BareJS pre-allocates a fixed array of Context objects during startup.
49
- * **The Masking Logic**: It utilizes **Bitwise Masking** (`idx & mask`) to recycle these objects instantly. For a pool of 1024, the engine performs a bitwise `AND` operation, which is hardware-accelerated and exponentially faster than standard modulo division.
50
- * **Result**: Zero GC pressure during the request-response cycle.
66
+ Traditional frameworks create new objects for every hit, triggering Garbage Collector (GC) spikes. BareJS pre-allocates a fixed array of Context objects and utilizes **Bitwise Masking** (`idx & mask`) for instant recycling.
51
67
 
52
68
  ### 2. Synchronous Fast-Path Execution
53
69
 
54
- The "Promise Tax" is a silent performance killer. Most modern frameworks wrap every route in an `async` wrapper, forcing a ~800ns penalty even for simple operations.
55
-
56
- * **Automatic Detection**: BareJS identifies if your handler is synchronous.
57
- * **Queue Bypassing**: Synchronous handlers bypass the Microtask queue entirely, executing directly on the call stack.
70
+ BareJS identifies if your handler is synchronous. Synchronous handlers bypass the Microtask queue entirely, executing directly on the call stack to avoid the "Promise Tax."
58
71
 
59
72
  ### 3. JIT Route Compilation (The "Baking" Phase)
60
73
 
61
- Unlike standard routers that perform string matching or tree traversal during the request, BareJS uses a Compilation Step.
62
-
63
- * **Static Jump Table**: During `app.listen()`, the entire route tree is transformed into a static jump table.
64
- * **Flat Middleware Chains**: Middleware is recursively "baked" into a single flat execution function, removing the need for array iteration while the server is running.
74
+ During `app.listen()`, the route tree is transformed into a **Static Jump Table**. Middleware is recursively "baked" into a single flat execution function, removing array iteration overhead at runtime.
65
75
 
66
76
  ---
67
77
 
68
78
  ## โšก Comprehensive Usage Guide
69
79
 
70
- BareJS provides a unified API. All core utilities, validators, and types are exported from a single point to ensure your code remains as clean as the engine is fast.
80
+ BareJS supports **Hybrid Handler Signatures**, allowing you to choose between maximum performance (Context) or standard Web APIs (Request/Params).
71
81
 
72
- ### ๐Ÿ“ฆ Installation
73
-
74
- ```bash
75
- bun add barejs
76
-
77
- ```
78
-
79
- ### ๐Ÿš€ Full Implementation Manual
82
+ ### ๐Ÿš€ Implementation Example
80
83
 
81
84
  ```typescript
82
- import { BareJS, typebox, zod, type Context } from 'barejs';
83
- import * as TB from '@sinclair/typebox';
85
+ import { BareJS, type Context, type Params } from 'barejs';
84
86
 
85
- // 1. Core Initialization
86
- // poolSize must be a power of 2 (1024, 2048, 4096) for bitwise masking
87
87
  const app = new BareJS({
88
- poolSize: 2048
89
- });
90
-
91
- // 2. Optimized Global Middleware
92
- app.use((ctx, next) => {
93
- ctx.set('server_id', 'BARE_NODE_01');
94
- return next();
88
+ poolSize: 2048 // Power of 2 required for hardware-accelerated masking
95
89
  });
96
90
 
97
- // 3. High-Speed Static Route (Sync Fast-Path: ~571ns)
98
- app.get('/ping', () => "pong");
91
+ // Style A: Zero-Allocation Context Pool (The 379ns Path)
92
+ app.get('/ctx', (ctx: Context) => ctx.json({ mode: "pooled" }));
99
93
 
100
- // 4. JIT Compiled Validation (TypeBox)
101
- // Data in ctx.body is automatically typed and validated
102
- const UserSchema = TB.Type.Object({
103
- username: TB.Type.String(),
104
- age: TB.Type.Number()
94
+ // Style B: Native Request/Params (Legacy/Standard compatibility)
95
+ app.get('/user/:id', (req: Request, params: Params) => {
96
+ return { id: params.id, method: "native" };
105
97
  });
106
98
 
107
- app.post('/register', typebox(UserSchema), (ctx: Context) => {
108
- const name = ctx.body.username;
109
- return { status: 'created', user: name };
110
- });
111
-
112
- // 5. Native Dynamic Parameters
113
- app.get('/user/:id', (ctx) => {
114
- return { userId: ctx.params.id };
115
- });
116
-
117
- // 6. Hardware-Accelerated WebSockets
118
- app.ws('/stream', {
119
- message(ws, msg) {
120
- ws.send(`BareJS Echo: ${msg}`);
121
- }
122
- });
123
-
124
- // 7. The Baking Phase
125
- // app.listen() triggers JIT compilation of all routes
126
99
  app.listen(3000);
127
- console.log("BareJS is screaming on port 3000");
128
100
 
129
101
  ```
130
102
 
131
103
  ---
132
104
 
133
- ## ๐Ÿ”Œ Advanced Deployment: BareJS JIT & Env
105
+ ## ๐Ÿ”Œ Advanced Deployment
134
106
 
135
- To achieve the benchmarked numbers, ensure you deploy using the BareJS optimized runtime environment variables.
107
+ To achieve the benchmarked numbers, ensure you deploy using the BareJS optimized runtime environment.
136
108
 
137
109
  | Variable | Description | Default |
138
110
  | --- | --- | --- |
@@ -142,7 +114,7 @@ To achieve the benchmarked numbers, ensure you deploy using the BareJS optimized
142
114
  **Deployment Command:**
143
115
 
144
116
  ```bash
145
- BARE_POOL_SIZE=4096 bun run index.ts
117
+ BARE_POOL_SIZE=4096 NODE_ENV=production bun run index.ts
146
118
 
147
119
  ```
148
120
 
@@ -153,10 +125,11 @@ BARE_POOL_SIZE=4096 bun run index.ts
153
125
  * [x] Zero-Allocation Context Pooling
154
126
  * [x] Bitwise Masking Optimization
155
127
  * [x] JIT Route Compilation
156
- * [x] Unified Export API (Typebox/Zod/Native)
128
+ * [x] Hybrid Handler Signatures (Context & Native)
157
129
  * [ ] **Direct Buffer Response**: Aiming for 400ns latency by writing directly to the TCP stream.
158
- * [ ] **Native Cluster Mode Support**: Automatic horizontal scaling across CPU cores.
130
+ * [-] **Native Cluster Mode Support**: Automatic horizontal scaling across CPU cores.
159
131
 
160
132
  ---
161
133
 
162
- **Maintained by [xarhang]** | **License: MIT**
134
+ **Maintained by [xarhang]** | **License: MIT**
135
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "barejs",
3
- "version": "0.1.26",
3
+ "version": "0.1.27",
4
4
  "author": "xarhang",
5
5
  "description": "High-performance JIT-specialized web framework for Bun",
6
6
  "main": "./dist/index.js",