1,011 karma · joined Feb 22, 2019 (7y ago) · 496 submissions
comment 1y ago · link · parent
comment 1y ago · link · parent
comment 1y ago · link · parent
I mean you're not wrong the serious people drop into assembly when they need too. Even if you work in a context where you can't or don't drop down into assembly being able to make your own compilers is incredibly useful.
comment 1y ago · link · parent
Anyone who spent time learning the AI tools over that period of time has basically wasted their time. Working with agents is nothing like prompt engineering. I imagine whatever comes after will be nothing like agents etc. Sounds like those who try to keep up with AI will be equally unemployed.
comment 1y ago · link · parent
comment 1y ago · link · parent
I put this together in a day and wasn't planning on it being on HN. So there's definitely some jank/UX polish.
For example the typing experience is nicer on chrome as the field sizes to the text.
comment 1y ago · link · parent
But because it's sqlite it's a single writer. Everything gets batched as one transaction every 100ms. The operations on a single chunk gets squashed into a single write.
Even without the squashing sqlite can handle 10000-20000+ updates/s because of the transaction batching.
With the chunk based squashing all edits to a chunk in that 100ms window become one update, so it can scale quite well.
comment 1y ago · link · parent
The scaling was preemptive as it was hitting 150% CPU (out of 200%). Needed to power down to rescale.
Now it's hovering at around 200% (out of 400%). About 80kb/s and 10 disk iops.
Everything goes via a sqlite db.
comment 1y ago · link · parent
1. Managing throughput with virtual threads (it's in Clojure, but it's using the underlying Java APIs)
https://andersmurphy.com/2024/05/06/clojure-managing-through...
comment 1y ago · link · parent
In our case the first time we needed to, we needed SSE and at the time there was no ring-jetty async interface (it's a long time ago so I'm forgetting the details) so we moved to aleph. Much later, we wanted to try out http-kit (self-indulgence) as we were operating behind a proxy anyway for performance reasons and it made a significant difference.
If we'd just started with http-kit that would have been fine. I guess it comes down to what features you need.
Also I 100% agree it's something ideally you would want to avoid a in the case of databases for example so much performance is left on the table because for some reason we want to be able to swap between SQLite, postgres and mySQL. Which in practice you never want to do.
comment 1y ago · link · parent
I have zero C experience and I have to say the coffi library (clojure macros that wrap Java 22's Panama FFI) is super slick. Next thing I know I'm using pointers and arenas. I'm still amazed that it all works.
To be fair the SQLite C API docs are incredible and made the whole experience much more enjoyable.
comment 1y ago · link · parent
I'd say the nice thing with the Clojure way of building your own stack is it becomes quite easy to swap parts out. On a previous project we swapped out our web server three different times with minimal changes (jetty -> aleph -> httpkit) as for the most part they all shared the same interface.
After a while you get good at seeing where you want things to be configurable and where you don't. It also gives you the confidence to roll your own micro stack/framework which means you are not dependent on third party aggregates to adopt new features.
445.
Clojure: SQLite C API with project Panama and Coffi(andersmurphy.com ↗)
10 points · by andersmurphy · 1y ago · 2 comments
comment 1y ago · link · parent
At some point I'll write up a blog post. Virtual scroll was surprisingly simple in the end and mostly leverages CSS grid.
The funny part, is it't not really about Datastar (I use a fraction of its features). It does make pushed based hypermedia simple which opens up a lot of options.
Clojure/JVM and SQLITE is where the interesting stuff is happening for me at least. I guess that's the nice thing, Datastar gets you back to programming in your favourite backend language of choice and then gets out of the way.
comment 1y ago · link · parent
2, 3 and 4 are spot on.
Theres's two connection pools one for reads one for write. Writes are batched every in a single transaction every 100ms and renders are pushed out to each connected user if there's a change max every 100ms (with back pressure). Reads are read only, and writes are transaction mode immediate.
Here's the schema:
CREATE TABLE IF NOT EXISTS cell(chunk_id INTEGER, cell_id INTEGER, state INTEGER, PRIMARY KEY (chunk_id, cell_id)) WITHOUT ROWID
And the options:
:cache_size 15625 :page_size 4096 :journal_mode "WAL" :synchronous "NORMAL" :temp_store "memory" :foreign_keys false
It's a pretty naive approach (1 billion rows).
Each user render is querying 2000 rows that then get converted to html elements, compressed and sent down on every change (including scroll). But, because renders are at most every 100ms changes effectively get batched.
On the whole this is relying on the brute force of SQLITE rather than anything too clever (eg: Hilbert curves or encoded chunks).
The point is that there could be any number of states. I wanted this to be quite general as for me this is more of a CRUD app demo.