Better HN
topnewbestaskshowjobs
Log inSign up

andersmurphy

1,011 karma · joined Feb 22, 2019 (7y ago) · 496 submissions

https://andersmurphy.com
Submissions

comment 1y ago · link · parent

Except you have no guarantees what client side compute is available. Sounds like a fools errand if you are looking for consistent performance.

comment 1y ago · link · parent

I think with brotli over SSE you can do just fine with 3G and bad networks without needing to be a SPA. Keeping almost all state on the sever make realtime collaborative apps much simpler than data sync you need with SPA. This demo has zero client side state and handles concurrent interactions over a billion data points [1].

- [1] https://checkboxes.andersmurphy.com

comment 1y ago · link · parent

My comparison wasn't about the tech. It was about the proponents of said tech. A lot of people who push AI use the same sorts of arguments that people used to push crypto.

comment 1y ago · link · parent

The article probably contains traces of blue.

comment 1y ago · link · parent

Or flat screens in cars. I just want a dial for my radio and real buttons.

comment 1y ago · link · parent

Thing is short/medium term VC subsidies require lots of users to embrace AI. If they don't the money dries up and you end up paying the full price for these models. Which are currently heavily discounted (this is an understatement). How much are you currently paying for your usage 20$/m? 200$/m? How does that look when it's 2000$/m? 20000$/m?

comment 1y ago · link · parent

Nice! Thanks for sharing. The expectation part reminds me of this jane street post [1].

- [1] https://blog.janestreet.com/the-joy-of-expect-tests/

comment 1y ago · link · parent

It's false comparison compilers are deterministic. The only probabilistic behavior I've seen has been for performance (query planning/branch prediction).

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

If the last few years of the AI hype cycle has taught me anything is there's massive late movers advantage.

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

Doesn’t have to be a choice it could just be the default. My billion cells/checkboxes[1] demos both use datastar and so are just over 10kb. It can make a big difference on mobile networks and 3G. I did my own tests and being over 14kb often meant an extra 3s load time on bad connections. The nice thing is I got this for free because the datastar maintainer cares about tcp slow star even though I might not.

- [1] https://checkboxes.andersmurphy.com

comment 1y ago · link · parent

This reminds me of crypto’s “have fun being poor”. Except now it’s “have fun being left behind/being unemployed”. The more things change the more things stay the same.

comment 1y ago · link · parent

Thank you for the kind words.

I'm planning on doing a write up on th se billion-foo style games at some point. It's been a fantastic learning experience.

comment 1y ago · link · parent

So that you can type in the field. It does shift the layout which is annoying.

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

I'm just heading off on holiday so if someone does... Please make a gif so I can watch it on my return.

There's a bad apple demo on the datastar site. Datastar's[1] streaming hypermedia is what makes this possible, that and good old Clojure and sqlite.

- [1] https://github.com/starfederation/datastar

comment 1y ago · link · parent

Oh, I mean they could try. It's a very big board. Probably possible though if someone is sufficiently motivated.

comment 1y ago · link · parent

So there's no rate limiting.

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

So the stack is datastar + clojure + sqlite + caddy on a hetzner VPS 2 core 2G.

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

And we're back on a 10$ VPS.

comment 1y ago · link · parent

Oh, fun. I wasn't expecting this on here so soon. It's very MVP and currently running on a 5$ VPS.

Happy to answer any questions.

comment 1y ago · link · parent

Good, question. The simple answer is there already is such a construct on the JVM already: the semaphore. People just forget it exists. I wrote an article about it a while back[1].

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

If you need the next level of UX dynamism and or realtime updates and or multiplayer. I've handled a billion checkboxes[1] with clojure, sqlite and datastar (realtime hypermedia) just fine.

[1] https://checkboxes.andersmurphy.com

comment 1y ago · link · parent

It's not. But, the fact that we could and it was straight forward still amazes me.

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

Author here.

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

A fantastic post! Enjoyed re-reading it.

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

That's a good idea. I should probably mention it's hypermedia too.

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

Datastar definitely makes CQRS/pushed based hypermedia simple.

But, SQLITE and JVM virtual threads are doing some heavy lifting. Clojure made it fun to write.

comment 1y ago · link · parent

Shame it's probably flagged. I imagine because I used the same url as my one million checkbox demo.

:(

comment 1y ago · link · parent

So it's less smart than that. The smaller page size sounds like a sensible probably a sensible call (that I didn't make).

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.

comment 1y ago · link · parent

Noted! It's on my list. But, it's probably more work than the whole project so far.
1
1314151617