Skip to content

Instantly share code, notes, and snippets.

@squarism
Last active November 6, 2022 19:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save squarism/c362e29137b690da19214172321c54e1 to your computer and use it in GitHub Desktop.
Save squarism/c362e29137b690da19214172321c54e1 to your computer and use it in GitHub Desktop.
Remix on Bun

Not a whole lot of info out there about this. I understand that bun is in beta at the moment. I just wanted to see where it's at. Remix doesn't really care too much about the runtime since it's tied to standard APIs. However, it's still SSR so ... how to run in prod etc?

Install Bun

bun.sh has the instructions but basically run the curl/bash one-liner command even if you are on zsh or fish.

bun --version
0.2.2

Make your app

You do not need bun to make your remix app.

npx create-remix@latest bun-load-test

Create whatever content you want. In this example, I made a useState counter button example to make it slightly more realistic but oha isn't going to render JSX. I also put a hardcoded loader function.

// index.tsx

export async function loader() {
  const data = [
    { name: "Grass", color: "green" },
    { name: "Air", color: "white" },
    { name: "Fire", color: "red" }
  ]
  return { data }
};

In the JSX ...

<ul>
  {elements.data.map((element, i) => {
    return (<li key={i}> {element.name} is {element.color}</li>)
  })}
</ul>

You probably want to make sure your app works in dev mode or pay attention to oha's error report. We aren't benchmarking 500s here. 😜

Build for Prod

bun run build
# Building Remix app in production mode...

# just an example of showing port override
# this is your app server in prod, the last argument is the build directory
# you could put a slash on it to make it clear but not needed
PORT=3001 NODE_ENV=production bun run remix-serve build/

Load Test

oha --http-version 2.0 -n 10000 -c 10 http://localhost:3001

Summary:
  ...
  Requests/sec:	2702.0305

Latency distribution:
  90% in 0.0049 secs
  95% in 0.0052 secs
  99% in 0.0058 secs

Other Notes

HMR doesn't work. This is really tricky with SSR. :( I didn't exect anything here but you can try anyway: bun run --hot dev

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment