From b677d3bb3d6c8fbb0b61621cc8ac53a7d68fa949 Mon Sep 17 00:00:00 2001 From: EuAndreh <eu@euandre.org> Date: Wed, 12 Feb 2020 09:04:53 -0300 Subject: wip --- ...2020-02-11-on-webassembly-killing-javascript.md | 206 +++++++++++++++++++++ tmp/add.c | 13 ++ tmp/add.h | 3 + tmp/api-posix.c | 15 ++ tmp/api-wasm.js | 7 + tmp/api.h | 2 + tmp/index.html | 14 ++ tmp/main.c | 12 ++ tmp/main.js | 1 + tmp/server.py | 15 ++ 10 files changed, 288 insertions(+) create mode 100644 _posts/2020-02-11-on-webassembly-killing-javascript.md create mode 100644 tmp/add.c create mode 100644 tmp/add.h create mode 100644 tmp/api-posix.c create mode 100644 tmp/api-wasm.js create mode 100644 tmp/api.h create mode 100644 tmp/index.html create mode 100644 tmp/main.c create mode 100644 tmp/main.js create mode 100755 tmp/server.py diff --git a/_posts/2020-02-11-on-webassembly-killing-javascript.md b/_posts/2020-02-11-on-webassembly-killing-javascript.md new file mode 100644 index 0000000..bab3b6e --- /dev/null +++ b/_posts/2020-02-11-on-webassembly-killing-javascript.md @@ -0,0 +1,206 @@ +--- +title: On WebAssembly killing JavaScript +date: 2020-02-11 +layout: post +lang: en +ref: on-webassembly-killing-javascript +--- +When discussing WebAssembly (WASM), I often see people portraiting it too much +as a JavaScript replacement, but I think this framing misses the point of some +of the aspects on how WASM can be a great tool: being a portability oportunity, +which means increasing the reach to code. + +If you think of WASM strictly as a optimization of JavaScript, that's where +you'll end up: WASM is the same as JavaScript, but faster. + +But there's a more interesting aspect (to me) of it: portability. That means you +can now write multiplatformr code that runs everywhere. I mean, everywhere, even +in the browser. Let's imagine how you could write SQLite and mke it run on the Web. + +# SQLite + + If I were to create, say, SQLite today, I would consider adding +web support for it. SQLite already is available everywhere[^1]. This is due to +it having very few dependencies and + +Imagine having writing SQLite today + +There are also other legimate uses of WASM, such as WASI and etc. + +Here's how I would start writing an application that could run on any POSIX +system and, on top of that, could run on the browser: + +``` +// api.h + +extern void platformDependentPersistInt(int); +extern int platformDependentRetrieveInt(); + + +// api-posix.c + +/* POSIX implementation of "api.h" interface to be used in non-web contexts */ + +#include <stdio.h> + +void platformDependentPersistInt(int n) { + FILE* fp = fopen("/tmp/persisted.txt", "w+"); + fprintf(fp, "%d", n); + fclose(fp); +} + +int platformDependentRetrieveInt() { + FILE* fp = fopen("/tmp/persisted.txt", "r"); + int persisted = fgetc(fp); + return persisted; +} + + +// api-wasm.js + +/* WASM implementation of "api.h" interface to be used in web contexts */ + +export const platformDependentPersistInt = (n) => + localStorage.setItem("persisted", n.toString()); + +export const platformDependentRetrieveInt = () => + parseInt(localStorage.getItem("persisted")); + + +// add.h + +int add(int a, int b); +void persistInt(int n); +int retrieveInt(); + + +// add.c + +#include "api.h" + +int add(int a, int b) { + return a * a + b; +} + +void persistInt(int n) { + platformDependentPersistInt(n); +} + +int retrieveInt() { + return platformDependentRetrieveInt(); +} +``` + +``` +// main.c + +#include <stdio.h> +#include "add.h" + +int main() { + int added = add(4, 5); + printf("Adding 4 and 5: %d\n", added); + + persistInt(6); + int persisted = retrieveInt(); + printf("Persisted number: %c\n", persisted); + return 0; +} + + +// index.html + +<script type="module"> + import * as api from "./api-wasm.js"; + + WebAssembly + .instantiateStreaming(fetch("add.wasm"), { env: api }) + .then(({instance: {exports}}) => { + const added = exports.add(4, 5); + console.log("Adding 4 and 5:", added); + + exports.persistInt(6); + const persisted = exports.retrieveInt(); + console.log("Persisted number:", persisted); + }); +</script> +``` + +In order to +``` +// server.py + +#!/usr/bin/env python +import SimpleHTTPServer +import SocketServer + +PORT = 8001 + +class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler): + pass + +Handler.extensions_map['.wasm'] = 'application/wasm' + +httpd = SocketServer.TCPServer(("", PORT), Handler) + +print "serving at port", PORT +httpd.serve_forever() +``` + +Dependency graph: +FIXME +api-posix.c api-wasm.js +api.h +add.h +add.c +main.c index.html + +Compiling and running the POSIX code: +```shell +$ clang -o add main.c add.c api-posix.c +$ ./add +Adding 4 and 5: 21 +Persisted number: 6 +``` + +Compiling and running the WASM +```shell +$ clang \ + --target=wasm32 \ + -nostdlib \ + -Wl,--no-entry \ + -Wl,--export-all \ + -Wl,--allow-undefined \ + -o add.wasm \ + add.c +$ ./server.py +``` + +After opening the browser, the console shows: +``` +Adding 4 and 5: 21 +Persisted number: 6 +``` + +Rust, C, Zig + +No Emscripten, no GC, no runtime + +Emscripten 11KB + +# Limitations + +"System call" cost in WebAssembly. + +WASM is very new, no flush guarantees. + +Confusing dependency tree + +AFAICT you can't package WASM with JavaScript. + + +[^1]: [Platforms supported by SQLite are](https://sqlite.org/features.html): + "Android, *BSD, iOS, Linux, Mac, Solaris, VxWorks, and Windows (Win32, + WinCE, WinRT) are supported out of the box. Easy to port to other systems". + +https://sqlite.org/selfcontained.html diff --git a/tmp/add.c b/tmp/add.c new file mode 100644 index 0000000..99267ed --- /dev/null +++ b/tmp/add.c @@ -0,0 +1,13 @@ +#include "api.h" + +int add(int a, int b) { + return a * a + b; +} + +void persistInt(int n) { + platformDependentPersistInt(n); +} + +int retrieveInt() { + return platformDependentRetrieveInt(); +} diff --git a/tmp/add.h b/tmp/add.h new file mode 100644 index 0000000..54c0712 --- /dev/null +++ b/tmp/add.h @@ -0,0 +1,3 @@ +int add(int a, int b); +void persistInt(int n); +int retrieveInt(); diff --git a/tmp/api-posix.c b/tmp/api-posix.c new file mode 100644 index 0000000..9f51967 --- /dev/null +++ b/tmp/api-posix.c @@ -0,0 +1,15 @@ +/* POSIX implementation of "api.h" interface to be used in non-web contexts */ + +#include <stdio.h> + +void platformDependentPersistInt(int n) { + FILE* fp = fopen("/tmp/persisted.txt", "w+"); + fprintf(fp, "%d", n); + fclose(fp); +} + +int platformDependentRetrieveInt() { + FILE* fp = fopen("/tmp/persisted.txt", "r"); + int persisted = fgetc(fp); + return persisted; +} diff --git a/tmp/api-wasm.js b/tmp/api-wasm.js new file mode 100644 index 0000000..50e1392 --- /dev/null +++ b/tmp/api-wasm.js @@ -0,0 +1,7 @@ +/* WASM implementation of "api.h" interface to be used in web contexts */ + +export const platformDependentPersistInt = (n) => + localStorage.setItem("persisted", n.toString()); + +export const platformDependentRetrieveInt = () => + parseInt(localStorage.getItem("persisted")); diff --git a/tmp/api.h b/tmp/api.h new file mode 100644 index 0000000..9b8d27d --- /dev/null +++ b/tmp/api.h @@ -0,0 +1,2 @@ +extern void platformDependentPersistInt(int); +extern int platformDependentRetrieveInt(); diff --git a/tmp/index.html b/tmp/index.html new file mode 100644 index 0000000..b222149 --- /dev/null +++ b/tmp/index.html @@ -0,0 +1,14 @@ +<script type="module"> + import * as api from "./api-wasm.js"; + + WebAssembly + .instantiateStreaming(fetch("add.wasm"), { env: api }) + .then(({instance: {exports}}) => { + const added = exports.add(4, 5); + console.log("Adding 4 and 5:", added); + + exports.persistInt(6); + const persisted = exports.retrieveInt(); + console.log("Persisted number:", persisted); + }); +</script> diff --git a/tmp/main.c b/tmp/main.c new file mode 100644 index 0000000..0ae18f7 --- /dev/null +++ b/tmp/main.c @@ -0,0 +1,12 @@ +#include <stdio.h> +#include "add.h" + +int main() { + int added = add(4, 5); + printf("Adding 4 and 5: %d\n", added); + + persistInt(6); + int persisted = retrieveInt(); + printf("Persisted number: %c\n", persisted); + return 0; +} diff --git a/tmp/main.js b/tmp/main.js new file mode 100644 index 0000000..3c105b2 --- /dev/null +++ b/tmp/main.js @@ -0,0 +1 @@ +import * as wasm from './' diff --git a/tmp/server.py b/tmp/server.py new file mode 100755 index 0000000..a76c833 --- /dev/null +++ b/tmp/server.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python +import SimpleHTTPServer +import SocketServer + +PORT = 8001 + +class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler): + pass + +Handler.extensions_map['.wasm'] = 'application/wasm' + +httpd = SocketServer.TCPServer(("", PORT), Handler) + +print "serving at port", PORT +httpd.serve_forever() -- cgit v1.2.3 From 9c2e6fd1338a5c03b2f4ba17d9b7dbe6fca08046 Mon Sep 17 00:00:00 2001 From: EuAndreh <eu@euandre.org> Date: Sun, 16 Feb 2020 13:22:02 -0300 Subject: Tweak --- _posts/2020-02-11-on-webassembly-killing-javascript.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/_posts/2020-02-11-on-webassembly-killing-javascript.md b/_posts/2020-02-11-on-webassembly-killing-javascript.md index bab3b6e..998c176 100644 --- a/_posts/2020-02-11-on-webassembly-killing-javascript.md +++ b/_posts/2020-02-11-on-webassembly-killing-javascript.md @@ -14,14 +14,14 @@ If you think of WASM strictly as a optimization of JavaScript, that's where you'll end up: WASM is the same as JavaScript, but faster. But there's a more interesting aspect (to me) of it: portability. That means you -can now write multiplatformr code that runs everywhere. I mean, everywhere, even +can now write multiplatforme code that runs everywhere. I mean, everywhere, even in the browser. Let's imagine how you could write SQLite and mke it run on the Web. # SQLite - If I were to create, say, SQLite today, I would consider adding -web support for it. SQLite already is available everywhere[^1]. This is due to -it having very few dependencies and +If I were to create, say, SQLite today, I would consider adding web support for +it. SQLite already is available almost everywhere[^1]. This is due to it having +very so few dependencies, Imagine having writing SQLite today @@ -148,7 +148,6 @@ httpd.serve_forever() ``` Dependency graph: -FIXME api-posix.c api-wasm.js api.h add.h -- cgit v1.2.3 From 7c55cb6c400db7aea9bfabbc6ffd8106499f4345 Mon Sep 17 00:00:00 2001 From: EuAndreh <eu@euandre.org> Date: Mon, 17 Feb 2020 21:51:16 -0300 Subject: WIP data formats stub draft --- _posts/2020-03-30-data-formats-a-comparison.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 _posts/2020-03-30-data-formats-a-comparison.md diff --git a/_posts/2020-03-30-data-formats-a-comparison.md b/_posts/2020-03-30-data-formats-a-comparison.md new file mode 100644 index 0000000..d69fee2 --- /dev/null +++ b/_posts/2020-03-30-data-formats-a-comparison.md @@ -0,0 +1,10 @@ +--- +title: Data formats: a comparison +date: 2020-03-30 +layout: post +lang: en +ref: data-formats-a-comparison +--- +Avro, EDN, etc. (The Language of the system) + +Look at column store data formats too? Parquet, ORC, etc. (Database Internals book) -- cgit v1.2.3 From 3422541b9abb343fe466b488b7c2dbc1fbf173ad Mon Sep 17 00:00:00 2001 From: EuAndreh <eu@euandre.org> Date: Sun, 23 Feb 2020 00:01:05 -0300 Subject: WIP Database Internals review --- .../2020-02-20-book-review-database-internals.md | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 _posts/2020-02-20-book-review-database-internals.md diff --git a/_posts/2020-02-20-book-review-database-internals.md b/_posts/2020-02-20-book-review-database-internals.md new file mode 100644 index 0000000..713c57b --- /dev/null +++ b/_posts/2020-02-20-book-review-database-internals.md @@ -0,0 +1,24 @@ +--- +title: Book review: "Database Internals" +date: 2020-02-20 +layout: post +lang: en +ref: book-review-database-internals +--- +I'm now reading the "Database Internals" book, by Alex Petrov. I'm liking it a +lot, and I have a similar feeling at the end of each chapter of when I was +reading "Designing Data-Intensive Applications": each chapter has some +references to other books, articles and resources, and I feel like I should go +and reach all of them to have a deeper understanding of the subject. + +It gives just enough historical background in the text itself to show that the +author does have knowledge in this area. + +# Chapter 1: Introduction and Overview + +The covering of basic vocabulary (column vs wide-column) is very good and +straightforward, and the fundamental trade-offs are shown very clearly, like +in-memory and disk-based storage, primary-keys and offset lookups, etc. + +Finishing this chapter I was happy with it's content and looking forward for a +more in-depth tour of many of the concepts presented here. -- cgit v1.2.3 From a9f1ed883ead6fe3c9d52c93d9de2059e96a1524 Mon Sep 17 00:00:00 2001 From: EuAndreh <eu@euandre.org> Date: Mon, 24 Feb 2020 02:26:34 -0300 Subject: Move draft posts to _drafts --- ...2020-02-11-on-webassembly-killing-javascript.md | 205 +++++++++++++++++++++ .../2020-02-20-book-review-database-internals.md | 24 +++ _drafts/2020-03-30-data-formats-a-comparison.md | 10 + ...2020-02-11-on-webassembly-killing-javascript.md | 205 --------------------- .../2020-02-20-book-review-database-internals.md | 24 --- _posts/2020-03-30-data-formats-a-comparison.md | 10 - 6 files changed, 239 insertions(+), 239 deletions(-) create mode 100644 _drafts/2020-02-11-on-webassembly-killing-javascript.md create mode 100644 _drafts/2020-02-20-book-review-database-internals.md create mode 100644 _drafts/2020-03-30-data-formats-a-comparison.md delete mode 100644 _posts/2020-02-11-on-webassembly-killing-javascript.md delete mode 100644 _posts/2020-02-20-book-review-database-internals.md delete mode 100644 _posts/2020-03-30-data-formats-a-comparison.md diff --git a/_drafts/2020-02-11-on-webassembly-killing-javascript.md b/_drafts/2020-02-11-on-webassembly-killing-javascript.md new file mode 100644 index 0000000..998c176 --- /dev/null +++ b/_drafts/2020-02-11-on-webassembly-killing-javascript.md @@ -0,0 +1,205 @@ +--- +title: On WebAssembly killing JavaScript +date: 2020-02-11 +layout: post +lang: en +ref: on-webassembly-killing-javascript +--- +When discussing WebAssembly (WASM), I often see people portraiting it too much +as a JavaScript replacement, but I think this framing misses the point of some +of the aspects on how WASM can be a great tool: being a portability oportunity, +which means increasing the reach to code. + +If you think of WASM strictly as a optimization of JavaScript, that's where +you'll end up: WASM is the same as JavaScript, but faster. + +But there's a more interesting aspect (to me) of it: portability. That means you +can now write multiplatforme code that runs everywhere. I mean, everywhere, even +in the browser. Let's imagine how you could write SQLite and mke it run on the Web. + +# SQLite + +If I were to create, say, SQLite today, I would consider adding web support for +it. SQLite already is available almost everywhere[^1]. This is due to it having +very so few dependencies, + +Imagine having writing SQLite today + +There are also other legimate uses of WASM, such as WASI and etc. + +Here's how I would start writing an application that could run on any POSIX +system and, on top of that, could run on the browser: + +``` +// api.h + +extern void platformDependentPersistInt(int); +extern int platformDependentRetrieveInt(); + + +// api-posix.c + +/* POSIX implementation of "api.h" interface to be used in non-web contexts */ + +#include <stdio.h> + +void platformDependentPersistInt(int n) { + FILE* fp = fopen("/tmp/persisted.txt", "w+"); + fprintf(fp, "%d", n); + fclose(fp); +} + +int platformDependentRetrieveInt() { + FILE* fp = fopen("/tmp/persisted.txt", "r"); + int persisted = fgetc(fp); + return persisted; +} + + +// api-wasm.js + +/* WASM implementation of "api.h" interface to be used in web contexts */ + +export const platformDependentPersistInt = (n) => + localStorage.setItem("persisted", n.toString()); + +export const platformDependentRetrieveInt = () => + parseInt(localStorage.getItem("persisted")); + + +// add.h + +int add(int a, int b); +void persistInt(int n); +int retrieveInt(); + + +// add.c + +#include "api.h" + +int add(int a, int b) { + return a * a + b; +} + +void persistInt(int n) { + platformDependentPersistInt(n); +} + +int retrieveInt() { + return platformDependentRetrieveInt(); +} +``` + +``` +// main.c + +#include <stdio.h> +#include "add.h" + +int main() { + int added = add(4, 5); + printf("Adding 4 and 5: %d\n", added); + + persistInt(6); + int persisted = retrieveInt(); + printf("Persisted number: %c\n", persisted); + return 0; +} + + +// index.html + +<script type="module"> + import * as api from "./api-wasm.js"; + + WebAssembly + .instantiateStreaming(fetch("add.wasm"), { env: api }) + .then(({instance: {exports}}) => { + const added = exports.add(4, 5); + console.log("Adding 4 and 5:", added); + + exports.persistInt(6); + const persisted = exports.retrieveInt(); + console.log("Persisted number:", persisted); + }); +</script> +``` + +In order to +``` +// server.py + +#!/usr/bin/env python +import SimpleHTTPServer +import SocketServer + +PORT = 8001 + +class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler): + pass + +Handler.extensions_map['.wasm'] = 'application/wasm' + +httpd = SocketServer.TCPServer(("", PORT), Handler) + +print "serving at port", PORT +httpd.serve_forever() +``` + +Dependency graph: +api-posix.c api-wasm.js +api.h +add.h +add.c +main.c index.html + +Compiling and running the POSIX code: +```shell +$ clang -o add main.c add.c api-posix.c +$ ./add +Adding 4 and 5: 21 +Persisted number: 6 +``` + +Compiling and running the WASM +```shell +$ clang \ + --target=wasm32 \ + -nostdlib \ + -Wl,--no-entry \ + -Wl,--export-all \ + -Wl,--allow-undefined \ + -o add.wasm \ + add.c +$ ./server.py +``` + +After opening the browser, the console shows: +``` +Adding 4 and 5: 21 +Persisted number: 6 +``` + +Rust, C, Zig + +No Emscripten, no GC, no runtime + +Emscripten 11KB + +# Limitations + +"System call" cost in WebAssembly. + +WASM is very new, no flush guarantees. + +Confusing dependency tree + +AFAICT you can't package WASM with JavaScript. + + +[^1]: [Platforms supported by SQLite are](https://sqlite.org/features.html): + "Android, *BSD, iOS, Linux, Mac, Solaris, VxWorks, and Windows (Win32, + WinCE, WinRT) are supported out of the box. Easy to port to other systems". + +https://sqlite.org/selfcontained.html diff --git a/_drafts/2020-02-20-book-review-database-internals.md b/_drafts/2020-02-20-book-review-database-internals.md new file mode 100644 index 0000000..8cac601 --- /dev/null +++ b/_drafts/2020-02-20-book-review-database-internals.md @@ -0,0 +1,24 @@ +--- +title: Book review - "Database Internals" +date: 2020-02-20 +layout: post +lang: en +ref: book-review-database-internals +--- +I'm now reading the "Database Internals" book, by Alex Petrov. I'm liking it a +lot, and I have a similar feeling at the end of each chapter of when I was +reading "Designing Data-Intensive Applications": each chapter has some +references to other books, articles and resources, and I feel like I should go +and reach all of them to have a deeper understanding of the subject. + +It gives just enough historical background in the text itself to show that the +author does have knowledge in this area. + +# Chapter 1: Introduction and Overview + +The covering of basic vocabulary (column vs wide-column) is very good and +straightforward, and the fundamental trade-offs are shown very clearly, like +in-memory and disk-based storage, primary-keys and offset lookups, etc. + +Finishing this chapter I was happy with it's content and looking forward for a +more in-depth tour of many of the concepts presented here. diff --git a/_drafts/2020-03-30-data-formats-a-comparison.md b/_drafts/2020-03-30-data-formats-a-comparison.md new file mode 100644 index 0000000..9df7db5 --- /dev/null +++ b/_drafts/2020-03-30-data-formats-a-comparison.md @@ -0,0 +1,10 @@ +--- +title: Data formats - a comparison +date: 2020-03-30 +layout: post +lang: en +ref: data-formats-a-comparison +--- +Avro, EDN, etc. (The Language of the system) + +Look at column store data formats too? Parquet, ORC, etc. (Database Internals book) diff --git a/_posts/2020-02-11-on-webassembly-killing-javascript.md b/_posts/2020-02-11-on-webassembly-killing-javascript.md deleted file mode 100644 index 998c176..0000000 --- a/_posts/2020-02-11-on-webassembly-killing-javascript.md +++ /dev/null @@ -1,205 +0,0 @@ ---- -title: On WebAssembly killing JavaScript -date: 2020-02-11 -layout: post -lang: en -ref: on-webassembly-killing-javascript ---- -When discussing WebAssembly (WASM), I often see people portraiting it too much -as a JavaScript replacement, but I think this framing misses the point of some -of the aspects on how WASM can be a great tool: being a portability oportunity, -which means increasing the reach to code. - -If you think of WASM strictly as a optimization of JavaScript, that's where -you'll end up: WASM is the same as JavaScript, but faster. - -But there's a more interesting aspect (to me) of it: portability. That means you -can now write multiplatforme code that runs everywhere. I mean, everywhere, even -in the browser. Let's imagine how you could write SQLite and mke it run on the Web. - -# SQLite - -If I were to create, say, SQLite today, I would consider adding web support for -it. SQLite already is available almost everywhere[^1]. This is due to it having -very so few dependencies, - -Imagine having writing SQLite today - -There are also other legimate uses of WASM, such as WASI and etc. - -Here's how I would start writing an application that could run on any POSIX -system and, on top of that, could run on the browser: - -``` -// api.h - -extern void platformDependentPersistInt(int); -extern int platformDependentRetrieveInt(); - - -// api-posix.c - -/* POSIX implementation of "api.h" interface to be used in non-web contexts */ - -#include <stdio.h> - -void platformDependentPersistInt(int n) { - FILE* fp = fopen("/tmp/persisted.txt", "w+"); - fprintf(fp, "%d", n); - fclose(fp); -} - -int platformDependentRetrieveInt() { - FILE* fp = fopen("/tmp/persisted.txt", "r"); - int persisted = fgetc(fp); - return persisted; -} - - -// api-wasm.js - -/* WASM implementation of "api.h" interface to be used in web contexts */ - -export const platformDependentPersistInt = (n) => - localStorage.setItem("persisted", n.toString()); - -export const platformDependentRetrieveInt = () => - parseInt(localStorage.getItem("persisted")); - - -// add.h - -int add(int a, int b); -void persistInt(int n); -int retrieveInt(); - - -// add.c - -#include "api.h" - -int add(int a, int b) { - return a * a + b; -} - -void persistInt(int n) { - platformDependentPersistInt(n); -} - -int retrieveInt() { - return platformDependentRetrieveInt(); -} -``` - -``` -// main.c - -#include <stdio.h> -#include "add.h" - -int main() { - int added = add(4, 5); - printf("Adding 4 and 5: %d\n", added); - - persistInt(6); - int persisted = retrieveInt(); - printf("Persisted number: %c\n", persisted); - return 0; -} - - -// index.html - -<script type="module"> - import * as api from "./api-wasm.js"; - - WebAssembly - .instantiateStreaming(fetch("add.wasm"), { env: api }) - .then(({instance: {exports}}) => { - const added = exports.add(4, 5); - console.log("Adding 4 and 5:", added); - - exports.persistInt(6); - const persisted = exports.retrieveInt(); - console.log("Persisted number:", persisted); - }); -</script> -``` - -In order to -``` -// server.py - -#!/usr/bin/env python -import SimpleHTTPServer -import SocketServer - -PORT = 8001 - -class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler): - pass - -Handler.extensions_map['.wasm'] = 'application/wasm' - -httpd = SocketServer.TCPServer(("", PORT), Handler) - -print "serving at port", PORT -httpd.serve_forever() -``` - -Dependency graph: -api-posix.c api-wasm.js -api.h -add.h -add.c -main.c index.html - -Compiling and running the POSIX code: -```shell -$ clang -o add main.c add.c api-posix.c -$ ./add -Adding 4 and 5: 21 -Persisted number: 6 -``` - -Compiling and running the WASM -```shell -$ clang \ - --target=wasm32 \ - -nostdlib \ - -Wl,--no-entry \ - -Wl,--export-all \ - -Wl,--allow-undefined \ - -o add.wasm \ - add.c -$ ./server.py -``` - -After opening the browser, the console shows: -``` -Adding 4 and 5: 21 -Persisted number: 6 -``` - -Rust, C, Zig - -No Emscripten, no GC, no runtime - -Emscripten 11KB - -# Limitations - -"System call" cost in WebAssembly. - -WASM is very new, no flush guarantees. - -Confusing dependency tree - -AFAICT you can't package WASM with JavaScript. - - -[^1]: [Platforms supported by SQLite are](https://sqlite.org/features.html): - "Android, *BSD, iOS, Linux, Mac, Solaris, VxWorks, and Windows (Win32, - WinCE, WinRT) are supported out of the box. Easy to port to other systems". - -https://sqlite.org/selfcontained.html diff --git a/_posts/2020-02-20-book-review-database-internals.md b/_posts/2020-02-20-book-review-database-internals.md deleted file mode 100644 index 713c57b..0000000 --- a/_posts/2020-02-20-book-review-database-internals.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -title: Book review: "Database Internals" -date: 2020-02-20 -layout: post -lang: en -ref: book-review-database-internals ---- -I'm now reading the "Database Internals" book, by Alex Petrov. I'm liking it a -lot, and I have a similar feeling at the end of each chapter of when I was -reading "Designing Data-Intensive Applications": each chapter has some -references to other books, articles and resources, and I feel like I should go -and reach all of them to have a deeper understanding of the subject. - -It gives just enough historical background in the text itself to show that the -author does have knowledge in this area. - -# Chapter 1: Introduction and Overview - -The covering of basic vocabulary (column vs wide-column) is very good and -straightforward, and the fundamental trade-offs are shown very clearly, like -in-memory and disk-based storage, primary-keys and offset lookups, etc. - -Finishing this chapter I was happy with it's content and looking forward for a -more in-depth tour of many of the concepts presented here. diff --git a/_posts/2020-03-30-data-formats-a-comparison.md b/_posts/2020-03-30-data-formats-a-comparison.md deleted file mode 100644 index d69fee2..0000000 --- a/_posts/2020-03-30-data-formats-a-comparison.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -title: Data formats: a comparison -date: 2020-03-30 -layout: post -lang: en -ref: data-formats-a-comparison ---- -Avro, EDN, etc. (The Language of the system) - -Look at column store data formats too? Parquet, ORC, etc. (Database Internals book) -- cgit v1.2.3 From e8d9017938cd020bcf62c359da0a531c984239b2 Mon Sep 17 00:00:00 2001 From: EuAndreh <eu@euandre.org> Date: Mon, 24 Feb 2020 02:27:40 -0300 Subject: Remove tmp/ --- tmp/add.c | 13 ------------- tmp/add.h | 3 --- tmp/api-posix.c | 15 --------------- tmp/api-wasm.js | 7 ------- tmp/api.h | 2 -- tmp/index.html | 14 -------------- tmp/main.c | 12 ------------ tmp/main.js | 1 - tmp/server.py | 15 --------------- 9 files changed, 82 deletions(-) delete mode 100644 tmp/add.c delete mode 100644 tmp/add.h delete mode 100644 tmp/api-posix.c delete mode 100644 tmp/api-wasm.js delete mode 100644 tmp/api.h delete mode 100644 tmp/index.html delete mode 100644 tmp/main.c delete mode 100644 tmp/main.js delete mode 100755 tmp/server.py diff --git a/tmp/add.c b/tmp/add.c deleted file mode 100644 index 99267ed..0000000 --- a/tmp/add.c +++ /dev/null @@ -1,13 +0,0 @@ -#include "api.h" - -int add(int a, int b) { - return a * a + b; -} - -void persistInt(int n) { - platformDependentPersistInt(n); -} - -int retrieveInt() { - return platformDependentRetrieveInt(); -} diff --git a/tmp/add.h b/tmp/add.h deleted file mode 100644 index 54c0712..0000000 --- a/tmp/add.h +++ /dev/null @@ -1,3 +0,0 @@ -int add(int a, int b); -void persistInt(int n); -int retrieveInt(); diff --git a/tmp/api-posix.c b/tmp/api-posix.c deleted file mode 100644 index 9f51967..0000000 --- a/tmp/api-posix.c +++ /dev/null @@ -1,15 +0,0 @@ -/* POSIX implementation of "api.h" interface to be used in non-web contexts */ - -#include <stdio.h> - -void platformDependentPersistInt(int n) { - FILE* fp = fopen("/tmp/persisted.txt", "w+"); - fprintf(fp, "%d", n); - fclose(fp); -} - -int platformDependentRetrieveInt() { - FILE* fp = fopen("/tmp/persisted.txt", "r"); - int persisted = fgetc(fp); - return persisted; -} diff --git a/tmp/api-wasm.js b/tmp/api-wasm.js deleted file mode 100644 index 50e1392..0000000 --- a/tmp/api-wasm.js +++ /dev/null @@ -1,7 +0,0 @@ -/* WASM implementation of "api.h" interface to be used in web contexts */ - -export const platformDependentPersistInt = (n) => - localStorage.setItem("persisted", n.toString()); - -export const platformDependentRetrieveInt = () => - parseInt(localStorage.getItem("persisted")); diff --git a/tmp/api.h b/tmp/api.h deleted file mode 100644 index 9b8d27d..0000000 --- a/tmp/api.h +++ /dev/null @@ -1,2 +0,0 @@ -extern void platformDependentPersistInt(int); -extern int platformDependentRetrieveInt(); diff --git a/tmp/index.html b/tmp/index.html deleted file mode 100644 index b222149..0000000 --- a/tmp/index.html +++ /dev/null @@ -1,14 +0,0 @@ -<script type="module"> - import * as api from "./api-wasm.js"; - - WebAssembly - .instantiateStreaming(fetch("add.wasm"), { env: api }) - .then(({instance: {exports}}) => { - const added = exports.add(4, 5); - console.log("Adding 4 and 5:", added); - - exports.persistInt(6); - const persisted = exports.retrieveInt(); - console.log("Persisted number:", persisted); - }); -</script> diff --git a/tmp/main.c b/tmp/main.c deleted file mode 100644 index 0ae18f7..0000000 --- a/tmp/main.c +++ /dev/null @@ -1,12 +0,0 @@ -#include <stdio.h> -#include "add.h" - -int main() { - int added = add(4, 5); - printf("Adding 4 and 5: %d\n", added); - - persistInt(6); - int persisted = retrieveInt(); - printf("Persisted number: %c\n", persisted); - return 0; -} diff --git a/tmp/main.js b/tmp/main.js deleted file mode 100644 index 3c105b2..0000000 --- a/tmp/main.js +++ /dev/null @@ -1 +0,0 @@ -import * as wasm from './' diff --git a/tmp/server.py b/tmp/server.py deleted file mode 100755 index a76c833..0000000 --- a/tmp/server.py +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env python -import SimpleHTTPServer -import SocketServer - -PORT = 8001 - -class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler): - pass - -Handler.extensions_map['.wasm'] = 'application/wasm' - -httpd = SocketServer.TCPServer(("", PORT), Handler) - -print "serving at port", PORT -httpd.serve_forever() -- cgit v1.2.3