Skip to content

Commit

Permalink
0.24.0
Browse files Browse the repository at this point in the history
  • Loading branch information
terrablue committed Sep 23, 2023
1 parent 4f25e56 commit f1bdd1c
Show file tree
Hide file tree
Showing 16 changed files with 167 additions and 27 deletions.
5 changes: 5 additions & 0 deletions docs/blog/release-024.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"title": "Release 0.24: Native Bun support",
"epoch": 1695477283000,
"author": "terrablue"
}
124 changes: 124 additions & 0 deletions docs/blog/release-024.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
Today we're announcing the availability of the Primate 0.24 preview release.
This release introduces native Bun support, enabling you to serve your
application significantly faster than before.

Bun is a new runtime based on JavaScriptCore and written in Zig. It has
recently had its first stable version, and has seen an uptick in interest ever
since.

!!!
If you're new to Primate, we recommend reading the [Getting started] page to
get an idea of the framework.
!!!

## Native Bun support

When Bun 1.0 came out, we were quick to test running Primate using Bun's NPM
compatibility. As it turned out, running `bun x primate` works as expected and
runs a Primate app without issue.

However, the real promise of Bun lies in its fast HTTP library implementation,
`Bun.serve`. Bun's NPM compatibility is great, but to get real speed gains over
Node, we have to use its native standard library.

As it turns out, Primate already uses a standard library of its own,
`runtime-compat`. As Primate is not the only project using it, we decided to
implement native Bun support into it and thus have Primate and other projects
benefit from it. This release uses the latest release of `runtime-compat`,
which uses Bun natively wherever possible and falls back to Node/NPM otherwise.

In addition to the core package, we have also patched `@primate/store` to use
Bun's native `bun:sqlite` module.

## Benchmarks

To illustrate the difference in serving Primate with native Bun, we created a
threeway benchmark: running Primate with NPM (`npx primate`), running it with
Bun's NPM compatibility (`bun x primate`), and running it natively with Bun
(`bun --bun x primate`).

Using the `ab` testing tool, we tested two scenarios, serving plain-text
content and an SSR-rendered Svelte page.

Our command for benchmarking was `ab -c 350 -n 100000 [url]`. That is, send
100000 requests with a concurrency of 350 requests at a time.

The app we used for testing was the [Primate template app][template-app].
To replicate the benchmarks, clone this repository and run the app.

In the following benchmarks, the quantities are:
* **TT** Time taken for tests (seconds)
* **RPS** Requests per second
* **TPR** Time per request (milliseconds) (mean, across all concurrent requests)
* **TR** Transfer rate, in Kbytes/second

### Plain-text

Command used `ab -c 350 -n 100000 http://localhost:6161/benchmark`

|Server |TT (s)|RPS |TPR (ms)|TR (Kbytes/s)
|---------------------|------|-------|--------|------------|
|`npx primate` |72.228|1384.50|0.722 |809.88 |
|`bun x primate` |72.688|1375.74|0.727 |804.75 |
|`bun --bun x primate`|18.488|5408.98|0.185 |3169.33 |

![](/bun-benchmark-plain.png)

### Svelte

Command used `ab -c 350 -n 100000 http://localhost:6161/benchmark/svelte`

|Server |TT (s) |RPS |TPR (ms)|TR (Kbytes/s)
|---------------------|-------|-------|--------|------------|
|`npx primate` |117.646|850.01 |1.176 |2560.81 |
|`bun x primate` |115.408|866.49 |1.154 |2610.48 |
|`bun --bun x primate`|29.981 |3335.40|0.300 |10058.33 |

![](/bun-benchmark-svelte.png)

## Caveats

In upcoming releases, we'll continue to improve Primate's support for Bun,
using native modules and functions wherever possible. Currently, if you rely on
`@primate/ws` for WebSockets in your application, you would have to stick to
NPM. Bun's native WebSocket implementation is radically different from the `ws`
package which `@primate/ws` uses, and unifying them was deemed out of scope for
this release. Please reach out if you specifically need WebSockets in your
application so we can better prioritize our work.

## Other changes

Consult the [full changelog][changelog] for a list of all relevant changes.

## Next on the road

Some of the things we plan to tackle in the upcoming weeks are,

* Add projections and relations to stores
* Multidriver transaction
* Introduce IDE TypeScript support
* Add a `command` hook that would allow modules to register command line
namespaces, to be able to run `npx primate [namespace] [command] [flags]`
* Use this new hook to create database migrations for SQL-flavored databases
* Extend `create-primate` with the ability to add new routes
* Add hydration and liveview support for `@primate/vue`
* Support the `multipart/form-data` content type
* Flesh out stores with default values, additional predicates and relations
between tables/collections
* Add more type variants

This list isn't exhaustive or binding. None, some or all of these features may
be included in 0.25, and other features may be prioritized according to
feedback.

## Fin

If you like Primate, consider [joining our channel #primate][irc] on
irc.libera.chat.

Otherwise, have a blast with the new version!

[Getting started]: /guide/getting-started
[irc]: https://web.libera.chat#primate
[changelog]: https://github.com/primatejs/primate/releases/tag/0.24.0
[template-app]: https://github.com/primatejs/app
9 changes: 8 additions & 1 deletion docs/guide/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ export default {
To start your app, run `npx -y primate@latest` and point your browser to
http://localhost:6161.

!!!
If you're a Bun user, you can take advantage of [significant speed gains][r24]
by running `bun --bun x primate` instead. The `--bun` flag makes sure Bun's
native implementations are used.
!!!

## Quick start

Before we continue, we recommend installing Primate by issuing `npm i primate`
Expand Down Expand Up @@ -171,8 +177,9 @@ Primate has an IRC channel at `#primate` on irc.libera.chat. You can use the
Feel free to open an issue on [Primate's issue tracker][issues] if you find a
bug or have a feature request.

[r24]: /blog/release-024
[repo]: https://github.com/primatejs/primate
[issues]: https://github.com/primatejs/primate/issues
[primate-app]: https://github.com/primatejs/app
[chat]: https://web.libera.chat/gamja#primate
[chat]: https://web.libera.chat#primate
[runtime-compat]: https://github.com/flogjs/std/tree/master/runtime-compat
16 changes: 8 additions & 8 deletions packages/create-primate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@
},
"type": "module",
"devDependencies": {
"@primate/esbuild": "^0.11.1",
"@primate/frontend": "^0.4.0",
"@primate/liveview": "^0.5.0",
"@primate/session": "^0.11.1",
"@primate/store": "^0.13.2",
"@primate/types": "^0.7.1",
"@primate/ws": "^0.5.1",
"@primate/esbuild": "^0.12.0",
"@primate/frontend": "^0.5.0",
"@primate/liveview": "^0.6.0",
"@primate/session": "^0.12.0",
"@primate/store": "^0.14.0",
"@primate/types": "^0.8.0",
"@primate/ws": "^0.6.0",
"better-sqlite3": "^8.6.0",
"mongodb": "^6.1.0",
"postgres": "^3.3.5",
"primate": "^0.23.2",
"primate": "^0.24.0",
"surrealdb.js": "^0.9.0"
}
}
4 changes: 2 additions & 2 deletions packages/esbuild/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@primate/esbuild",
"version": "0.11.1",
"version": "0.12.0",
"description": "Primate esbuild module",
"homepage": "https://primatejs.com/modules/esbuild",
"bugs": "https://github.com/primatejs/primate/issues",
Expand All @@ -19,7 +19,7 @@
"runtime-compat": "^0.29.0"
},
"peerDependencies": {
"primate": "0.23"
"primate": "0.24"
},
"type": "module",
"exports": "./src/exports.js"
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@primate/frontend",
"version": "0.4.2",
"version": "0.5.0",
"description": "Primate frontend code",
"bugs": "https://github.com/primatejs/primate/issues",
"license": "MIT",
Expand Down Expand Up @@ -37,7 +37,7 @@
"handlebars": "4",
"htmx.org": "1",
"marked": "9",
"primate": "0.23",
"primate": "0.24",
"react": "18",
"react-dom": "18",
"solid-js": "1",
Expand Down
4 changes: 2 additions & 2 deletions packages/liveview/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@primate/liveview",
"version": "0.5.0",
"version": "0.6.0",
"description": "Primate liveview module",
"homepage": "https://primatejs.com/modules/liveview",
"bugs": "https://github.com/primatejs/primate/issues",
Expand All @@ -15,7 +15,7 @@
"directory": "packages/liveview"
},
"peerDependencies": {
"primate": "0.23"
"primate": "0.24"
},
"type": "module",
"exports": {
Expand Down
2 changes: 1 addition & 1 deletion packages/primate/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "primate",
"version": "0.23.2",
"version": "0.24.0",
"description": "Expressive, minimal and extensible web framework",
"homepage": "https://primatejs.com",
"bugs": "https://github.com/primatejs/primate/issues",
Expand Down
4 changes: 2 additions & 2 deletions packages/session/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@primate/session",
"version": "0.11.1",
"version": "0.12.0",
"description": "Primate session module",
"homepage": "https://primatejs.com/modules/session",
"bugs": "https://github.com/primatejs/primate/issues",
Expand All @@ -18,7 +18,7 @@
"runtime-compat": "^0.29.0"
},
"peerDependencies": {
"primate": "0.23"
"primate": "0.24"
},
"type": "module",
"exports": "./src/exports.js"
Expand Down
6 changes: 3 additions & 3 deletions packages/store/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@primate/store",
"version": "0.13.2",
"version": "0.14.0",
"description": "Primate data store module",
"homepage": "https://primatejs.com/modules/store",
"bugs": "https://github.com/primatejs/primate/issues",
Expand All @@ -22,7 +22,7 @@
"runtime-compat": "^0.29.0"
},
"devDependencies": {
"@primate/types": "^0.7.1",
"@primate/types": "^0.8.0",
"better-sqlite3": "^8.6.0",
"mongodb": "^6.1.0",
"postgres": "^3.3.5",
Expand All @@ -32,7 +32,7 @@
"better-sqlite3": "8",
"mongodb": "6",
"postgres": "3",
"primate": "0.23",
"primate": "0.24",
"surrealdb.js": "0.9"
},
"peerDependenciesMeta": {
Expand Down
4 changes: 2 additions & 2 deletions packages/types/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@primate/types",
"version": "0.7.1",
"version": "0.8.0",
"description": "Primate types module",
"homepage": "https://primatejs.com/modules/types",
"bugs": "https://github.com/primatejs/primate/issues",
Expand All @@ -18,7 +18,7 @@
"runtime-compat": "^0.29.0"
},
"peerDependencies": {
"primate": "0.23"
"primate": "0.24"
},
"type": "module",
"exports": "./src/exports.js"
Expand Down
4 changes: 2 additions & 2 deletions packages/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"private": true,
"dependencies": {
"marked": "^9.0.3",
"primate": "^0.23.2",
"priss": "^0.21.2",
"primate": "^0.24.0",
"priss": "^0.22.0",
"svelte": "^4.2.1"
},
"scripts": {
Expand Down
Binary file added packages/website/static/bun-benchmark-plain.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/website/static/bun-benchmark-svelte.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions packages/website/static/master.css
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,10 @@ img.background {
border-top: 1px solid #0d0905;
}

.dark article.blog img {
filter: invert(88%);
}

@media (max-width: 428px) {
.home .title {
display: none;
Expand Down
4 changes: 2 additions & 2 deletions packages/ws/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@primate/ws",
"version": "0.5.2",
"version": "0.6.0",
"description": "Primate WebSocket module",
"homepage": "https://primatejs.com/modules/ws",
"bugs": "https://github.com/primatejs/primate/issues",
Expand All @@ -20,7 +20,7 @@
"ws": "^8.14.2"
},
"peerDependencies": {
"primate": "0.23"
"primate": "0.24"
},
"type": "module",
"exports": "./src/exports.js"
Expand Down

0 comments on commit f1bdd1c

Please sign in to comment.