Commit Graph

13361 Commits

Author SHA1 Message Date
Alistair Smith
f01ed9acbb format 2025-08-20 13:17:38 -07:00
Alistair Smith
f7c7e54616 upload tarballs 2025-08-20 13:17:38 -07:00
Alistair Smith
5abfc734c1 some clear dependency packages for test 2025-08-20 13:17:38 -07:00
Alistair Smith
fa55574264 fast poll freq 2025-08-20 13:17:38 -07:00
Alistair Smith
2e86694ace poll 2025-08-20 13:17:38 -07:00
Alistair Smith
f0a7f7a0c0 change 2025-08-20 13:17:38 -07:00
Alistair Smith
e2f60b2085 rm for now 2025-08-20 13:17:38 -07:00
Alistair Smith
9b806aa501 transitive changes 2025-08-20 13:17:38 -07:00
Alistair Smith
d2454329ed run→test 2025-08-20 13:17:38 -07:00
Alistair Smith
86660e0ec5 docs + fix tests 2025-08-20 13:17:38 -07:00
Alistair Smith
e930a9f9c1 dont deadlock in some cases 2025-08-20 13:17:38 -07:00
Alistair Smith
9d58cdc20b clean 2025-08-20 13:17:38 -07:00
Alistair Smith
e447c598ba onInstall → scan 2025-08-20 13:17:38 -07:00
Alistair Smith
84fe8d3f64 changes 2025-08-20 13:17:38 -07:00
Alistair Smith
aaa271d041 level is not optional 2025-08-20 13:17:38 -07:00
Alistair Smith
15543cafc8 loadsa tests 2025-08-20 13:17:38 -07:00
autofix-ci[bot]
04b86acfab [autofix.ci] apply automated fixes 2025-08-20 13:17:38 -07:00
Alistair Smith
ccc8a24081 tests 2025-08-20 13:17:38 -07:00
Alistair Smith
db5fcf16da move to post-resolution during install 2025-08-20 13:17:38 -07:00
Alistair Smith
f045dfecf4 tests 2025-08-20 13:17:38 -07:00
Alistair Smith
5093ad89e1 fix 2025-08-20 13:17:38 -07:00
Alistair Smith
e84be1da7c works 2025-08-20 13:17:37 -07:00
Alistair Smith
59f4158981 no integrity 2025-08-20 13:17:37 -07:00
Alistair Smith
d75845325b changes 2025-08-20 13:17:37 -07:00
Alistair Smith
c3d05ea3d9 check 2025-08-20 13:17:37 -07:00
Alistair Smith
dd30128099 import 2025-08-20 13:17:37 -07:00
Alistair Smith
5ed3f1b21e change 2025-08-20 13:17:37 -07:00
Alistair Smith
7ef2f047f9 revert 2025-08-20 13:17:37 -07:00
autofix-ci[bot]
98519215b5 [autofix.ci] apply automated fixes 2025-08-20 13:17:37 -07:00
Alistair Smith
28e3b88108 for now 2025-08-20 13:17:37 -07:00
Alistair Smith
c2ea7b3c10 test 2025-08-20 13:17:37 -07:00
Alistair Smith
505ed59d97 fix 2025-08-20 13:17:37 -07:00
autofix-ci[bot]
55336c2d93 [autofix.ci] apply automated fixes 2025-08-20 13:17:37 -07:00
Alistair Smith
5d18e47190 rough initial impl 2025-08-20 13:17:37 -07:00
Alistair Smith
fc30e6936a test 2025-08-20 13:17:37 -07:00
Alistair Smith
6b669ea431 test update 2025-08-20 13:17:37 -07:00
Alistair Smith
91d0930e68 does error 2025-08-20 13:17:37 -07:00
Alistair Smith
7e0458bc23 add not install 2025-08-20 13:17:37 -07:00
Alistair Smith
0cf158b486 msg 2025-08-20 13:17:37 -07:00
Alistair Smith
7628d105d4 bunfig related 2025-08-20 13:17:37 -07:00
Alistair Smith
233198999a this didn't work 2025-08-20 13:17:37 -07:00
Alistair Smith
72e1cad342 update test 2025-08-20 13:17:37 -07:00
Alistair Smith
2e7a55188b Some high level changes/loose test 2025-08-20 13:17:36 -07:00
Alistair Smith
f279855ad6 update comments 2025-08-20 13:17:36 -07:00
Alistair Smith
c534d67119 comment 2025-08-20 13:17:36 -07:00
Alistair Smith
1856124e28 sketch types for Bun.Install.Security 2025-08-20 13:17:34 -07:00
Michael H
d354714791 Plugins + cross-compilation + Bun.build API support for Bun.build({compile}) (#21915)
### What does this PR do?

in the name

### How did you verify your code works?

tests, but using ci to see if anything else broke

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
2025-08-20 01:25:49 -07:00
robobun
e7672b2d04 Add string fast path for postMessage and structuredClone (#21926)
## Summary

Implements a string fast path optimization for `postMessage` and
`structuredClone` operations that provides significant performance
improvements for string-only data transfer, along with various bug fixes
and infrastructure improvements.

## Key Performance Improvements

**postMessage with Workers:**
- **Small strings (11 chars):** ~5% faster (572ns vs 599ns)
- **Medium strings (14KB):** **~2.7x faster** (528ns vs 1.40μs) 
- **Large strings (3MB):** **~660x faster** (540ns vs 356μs)

**Compared to Node.js postMessage:**
- Similar performance for small strings
- Competitive for medium strings  
- **~455x faster** for large strings (540ns vs 245μs)

## Implementation Details

The optimization adds a **string fast path** that bypasses full
structured cloning serialization when:
- Input is a pure string (`value.isString()`)
- No transfer list or message ports are involved
- Not being stored persistently

### Core Changes

**String Thread-Safety Utilities (`BunString.cpp/h`):**
- `isCrossThreadShareable()` - Checks if string can be safely shared
across threads
- `toCrossThreadShareable()` - Converts strings to thread-safe form via
`isolatedCopy()`
- Handles edge cases: atoms, symbols, substring slices, external buffers

**Serialization Fast Path (`SerializedScriptValue.cpp`):**
- New `m_fastPathString` field stores string data directly
- Bypasses full object serialization machinery for pure strings
- Creates isolated copies for cross-thread safety

**Deserialization Fast Path:**
- Directly returns JSString from stored string data
- Avoids parsing serialized byte streams

**Updated Flags System (`JSValue.zig`, `Serialization.cpp`):**
- Replaces boolean `forTransfer` with structured `SerializedFlags`
- Supports `forCrossProcessTransfer` and `forStorage` distinctions

**Structured Clone Infrastructure:**
- Moved `structuredClone` implementation to dedicated
`StructuredClone.cpp`
- Added `jsFunctionStructuredCloneAdvanced` for testing with custom
flags
- Improved class serialization compatibility checks (`isForTransfer`,
`isForStorage`)

**IPC Improvements (`ipc.zig`):**
- Fixed race conditions in `SendQueue` by deferring cleanup to next tick
- Proper fd ownership handling with `bun.take()`
- Cached IPC serialize/parse functions for better performance

**BlockList Thread Safety Fixes (`BlockList.zig`):**
- Fixed potential deadlocks by moving mutex locking inside methods
- Added atomic `estimated_size` counter to avoid lock during GC
- Corrected pointer handling in comparison functions
- Improved GC safety in `rules()` method

## Benchmark Results

```
❯ bun-21926 bench/string-postmessage.mjs  # This branch
postMessage(11 chars string)  572.24 ns/iter
postMessage(14 KB string)     527.55 ns/iter  ← ~2.7x faster
postMessage(3 MB string)      539.70 ns/iter  ← ~660x faster

❯ bun-1.2.20 bench/string-postmessage.mjs  # Previous
postMessage(11 chars string)  598.76 ns/iter
postMessage(14 KB string)       1.40 µs/iter
postMessage(3 MB string)      356.38 µs/iter

❯ node bench/string-postmessage.mjs       # Node.js comparison  
postMessage(11 chars string)  569.63 ns/iter
postMessage(14 KB string)       1.46 µs/iter
postMessage(3 MB string)      245.46 µs/iter
```

**Key insight:** The fast path achieves **constant time performance**
regardless of string size (~540ns), while traditional serialization
scales linearly with data size.

## Test Coverage

**New Tests:**
- `test/js/web/structured-clone-fastpath.test.ts` - Fast path memory
usage validation
- `test/js/web/workers/structuredClone-classes.test.ts` - Comprehensive
class serialization tests
  - Tests ArrayBuffer transferability 
  - Tests BunFile cloning with storage/transfer restrictions
  - Tests net.BlockList cloning behavior
  - Validates different serialization contexts (default, worker, window)

**Enhanced Tests:**
- `test/js/web/workers/structured-clone.test.ts` - Multi-function
testing
- Tests `structuredClone`, `jscSerializeRoundtrip`, and cross-process
serialization
  - Validates consistency across different serialization paths
- `test/js/node/cluster.test.ts` - Better error handling and debugging

**Benchmarks:**
- `bench/string-postmessage.mjs` - Worker postMessage performance
comparison
- `bench/string-fastpath.mjs` - Fast path vs traditional serialization
comparison

## Bug Fixes

**BlockList Threading Issues:**
- Fixed potential deadlocks when multiple threads access BlockList
simultaneously
- Moved mutex locks inside methods rather than holding across entire
function calls
- Added atomic size tracking for GC compatibility
- Fixed comparison function pointer handling

**IPC Race Conditions:**
- Fixed race condition where `SendQueue._onAfterIPCClosed()` could be
called on wrong thread
- Deferred cleanup operations to next tick using task queue
- Improved file descriptor ownership with proper `bun.take()` usage

**Structured Clone Compatibility:**
- Enhanced class serialization with proper transfer/storage mode
checking
- Fixed edge cases where non-transferable objects were incorrectly
handled
- Added better error reporting for unsupported clone operations

## Technical Notes

- Thread safety ensured via `String.isolatedCopy()` for cross-VM
transfers
- Memory cost calculation updated to account for string references
- Maintains full compatibility with existing structured clone semantics
- Does not affect object serialization or transfer lists
- Proper cleanup and error handling throughout IPC pipeline

---------

Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Meghan Denny <meghan@bun.sh>
2025-08-20 00:25:00 -07:00
robobun
7110dc10a4 Fix UTF-16 encoding crash with odd-length byte arrays (#21966)
## Summary
- Fixes a panic: "exact division produced remainder" that occurs when
reading files with odd number of bytes using utf16le/ucs2 encoding
- The crash happened in `encoding.zig:136` when
`std.mem.bytesAsSlice(u16, input)` was called on a byte slice with odd
length
- Fixed by properly checking for odd-length input and truncating to the
nearest even length

## Test plan
- Added regression tests in
`test/regression/issue/utf16-encoding-crash.test.ts`
- Tests verify that reading files with odd byte counts doesn't crash
- Tests verify correct truncation behavior matches Node.js expectations
- Verified edge cases (0, 1 byte inputs) return empty strings

## Root Cause
The original code checked `if (input.len / 2 == 0)` which only caught 0
and 1-byte inputs, but `std.mem.bytesAsSlice(u16, input)` panics on any
odd-length input (3, 5, 7, etc. bytes).

## Fix Details
- Changed condition to check `input.len % 2 != 0` for any odd length
- Truncate odd-length inputs to the nearest even length for valid UTF-16
processing
- Handle edge cases by returning empty string for 0 or 1-byte inputs

🤖 Generated with [Claude Code](https://claude.ai/code)

---------

Co-authored-by: Claude Bot <claude-bot@bun.sh>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
Co-authored-by: Dylan Conway <dylan.conway567@gmail.com>
2025-08-20 00:02:14 -07:00
Alistair Smith
784271f85e SQLite in Bun.sql (#21640)
### What does this PR do?

Support sqlite in the Bun.sql API

Fixes #18951
Fixes #19701

### How did you verify your code works?

tests

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
2025-08-19 23:15:53 -07:00