Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip rewrite web streams API in c++ #15843

Draft
wants to merge 46 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
fbe1895
wip
Jarred-Sumner Dec 18, 2024
64df1de
more
Jarred-Sumner Dec 18, 2024
83e813f
Create ReadableStream.mjs
Jarred-Sumner Dec 18, 2024
110f94d
Merge branch 'main' into jarred/streamy-
Jarred-Sumner Dec 19, 2024
14e8c47
Update BunWritableStream.cpp
Jarred-Sumner Dec 19, 2024
38f98d3
Create .cursorignore
Jarred-Sumner Dec 19, 2024
3a39b18
wip
Jarred-Sumner Dec 19, 2024
c2b9ea2
more
Jarred-Sumner Dec 19, 2024
be1631d
Fix more errors
Jarred-Sumner Dec 19, 2024
7bff270
Update BunReadableStreamDefaultController.h
Jarred-Sumner Dec 19, 2024
33db844
more
Jarred-Sumner Dec 19, 2024
7c2b935
more
Jarred-Sumner Dec 19, 2024
fcb0dae
Update BunWritableStream.cpp
Jarred-Sumner Dec 19, 2024
c76ad94
more
Jarred-Sumner Dec 19, 2024
9894605
Update .cursorignore
Jarred-Sumner Dec 20, 2024
b152f07
move some things around
Jarred-Sumner Dec 20, 2024
a03502e
More files
Jarred-Sumner Dec 20, 2024
bdab548
More files
Jarred-Sumner Dec 20, 2024
d76d8b7
More files
Jarred-Sumner Dec 20, 2024
20c8bb1
More files
Jarred-Sumner Dec 20, 2024
c25bb29
Update BunReadableStream.h
Jarred-Sumner Dec 20, 2024
7997706
More files
Jarred-Sumner Dec 20, 2024
5fc5baa
More files
Jarred-Sumner Dec 20, 2024
4f6b066
Update BunWritableStreamConstructor.h
Jarred-Sumner Dec 20, 2024
49647de
More files
Jarred-Sumner Dec 20, 2024
d03f88a
More
Jarred-Sumner Dec 20, 2024
cfc3907
Update BunReadableStreamDefaultReaderConstructor.cpp
Jarred-Sumner Dec 20, 2024
122e875
Update BunReadableStreamDefaultController.cpp
Jarred-Sumner Dec 20, 2024
00b9b94
more
Jarred-Sumner Dec 20, 2024
665e1f8
more
Jarred-Sumner Dec 20, 2024
f08c1a3
Merge branch 'main' into jarred/streamy-
Jarred-Sumner Dec 26, 2024
6c4d833
more
Jarred-Sumner Dec 26, 2024
c04bef6
It compiled
Jarred-Sumner Dec 26, 2024
9127371
delete probably too much code
Jarred-Sumner Dec 26, 2024
98e130a
there's more
Jarred-Sumner Dec 26, 2024
dbdceef
more
Jarred-Sumner Dec 27, 2024
243b087
much
Jarred-Sumner Dec 27, 2024
cfcef4b
wip
Jarred-Sumner Dec 27, 2024
9bea782
it compiled once again
Jarred-Sumner Dec 27, 2024
44714cb
We are streaming
Jarred-Sumner Dec 27, 2024
c22d1a6
Update BunReadableStreamDefaultReader.cpp
Jarred-Sumner Dec 27, 2024
44465a8
Update BunReadableStream.h
Jarred-Sumner Dec 27, 2024
1e34965
sort of owrks
Jarred-Sumner Dec 27, 2024
1f6e67c
working better
Jarred-Sumner Dec 27, 2024
bdcb6ec
Update ReadableStream.mjs
Jarred-Sumner Dec 27, 2024
4e5cae8
`bun run prettier:extra`
Jarred-Sumner Dec 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion .cursorignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
vendor
src/bun.js/bindings/webcore/JSReadableStream.h
src/bun.js/bindings/webcore/JSReadableStreamDefaultReader.h
src/bun.js/bindings/webcore/JSReadableStreamDefaultReader.cpp
src/bun.js/bindings/webcore/JSReadableStreamDefaultController.h
src/bun.js/bindings/webcore/JSReadableStreamDefaultController.cpp
src/bun.js/bindings/webcore/JSReadableStream.h
src/bun.js/bindings/webcore/JSWritableStreamDefaultWriter.h
src/bun.js/bindings/webcore/JSWritableStreamDefaultWriter.cpp
src/bun.js/bindings/webcore/JSWritableStreamDefaultController.h
src/bun.js/bindings/webcore/JSWritableStreamDefaultController.cpp
src/bun.js/bindings/webcore/JSTransformStreamDefaultController.h
src/bun.js/bindings/webcore/JSTransformStreamDefaultController.cpp
src/bun.js/bindings/webcore/JSTransformStream.h
src/bun.js/bindings/webcore/JSTransformStream.cpp
# Add directories or file patterns to ignore during indexing (e.g. foo/ or *.csv)
bench
vendor
*-fixture.{js,ts}
zig-cache
packages/bun-uws/fuzzing
build
build
91 changes: 91 additions & 0 deletions bench/snippets/ReadableStream.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import React from "react";
import { renderToReadableStream } from "react-dom/server.browser";
import { bench, run } from "../runner.mjs";

const reactElement = React.createElement(
"body",
null,
React.createElement("div", null, React.createElement("address", null, "hi")),
);

bench("ReactDOM.renderToReadableStream", async () => {
const stream = await renderToReadableStream(reactElement);
await stream.allReady;

const reader = stream.getReader();
while (true) {
const { value, done } = await reader.read();

if (done) {
break;
}
}
});

bench("ReadableStream (3 reads)", async () => {
const stream = new ReadableStream({
start(controller) {
controller.enqueue("Hello");
},
pull(controller) {
controller.enqueue("World");

controller.close();
},
});

const reader = stream.getReader();

var { value, done } = await reader.read();
({ value, done } = await reader.read());
({ value, done } = await reader.read());

if (!done) {
throw new Error("failed");
}
});

bench("ReadableStream (1 read -> 1 pull) x 32 * 1024 ", async () => {
let next = Promise.withResolvers();
let remaining = 32 * 1024;
const stream = new ReadableStream({
pull(controller) {
next = Promise.withResolvers();
controller.enqueue("Hello");
next.resolve();
if (remaining-- === 0) {
controller.close();
}
},
});

const reader = stream.getReader();

while (true) {
var { value, done } = await reader.read();
if (done) {
break;
}
await next.promise;
}
});
{
let next = Promise.withResolvers();

const stream = new ReadableStream({
pull(controller) {
next = Promise.withResolvers();
next.resolve();
controller.enqueue("Hello");
},
});

const reader = stream.getReader();
bench("ReadableStream (1 read -> 1 pull) same instance x 10 times ", async () => {
for (let i = 0; i < 10; i++) {
var { value, done } = await reader.read();
await next.promise;
}
});
}
await run();
12 changes: 12 additions & 0 deletions src/bun.js/bindings/BunPromiseInlines.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

namespace Bun {

static inline JSC::JSPromise* createFulfilledPromise(JSC::JSGlobalObject* globalObject, JSC::JSValue value)
{
JSC::JSPromise* promise = JSC::JSPromise::create(globalObject->vm(), globalObject->promiseStructure());
promise->fulfill(globalObject, value);
return promise;
}

}
Loading