kig
Joined 14 years ago
Joined 14 years ago
I'm cooking something faster but depends on the job situation and funding whether I have time to spend on it.
Napkin math: QR codes encode 0.75 bits per module, each module needs about 3 pixels of camera resolution, and the temporal resolution is quite dodgy as well, maybe 0.25 * min(cameraHz, screenHz). So if everything is perfect, 44 kB/s at 60Hz per a 500x500 pixel patch. I've seen ~250 kB/s when a 1920x1080@60 transfer is working well. At 4k@30, you might reach 0.5 MB/s. If you throw in the 2x subsampled UV channels to transfer data as well, you might get an extra 50%.
I've been noodling on https://qr-send.com which is a slightly more polished version of the "erasure fountain codes + stream of QRs"-idea, inspired by divan's Txqr posts but using Wirehair FEC for the fountain code (basically: you receive ~file size bytes via QR codes and it magically assembles them into the source file regardless of missed codes).
It's an offline-first progressive web app and there are native & wasm builds for the sender. The browser-to-browser transfer falls up to WebRTC when possible because 30 MB/s over wifi beats a 100 kB/s QR stream. The QR scanner is a heavily-optimized WASM build of zbar, scanning at 60 fps on mobile & multiple QRs per frame (but it's finicky! Work in progress.)
I once wrote a prototype async IO runtime for GLSL (https://github.com/kig/glslscript), it used a shared memory buffer and spinlocks. The GPU would write "hey do this" into the IO buffer, then go about doing other stuff until it needed the results, and spinlock to wait for the results to arrive from the CPU. I remember this being a total pain, as you need to be aware of how PCIe DMA works on some level: having your spinlock int written to doesn't mean that the rest of the memory write has finished.
The brain is about 0.1 trillion cells, of which 0.02 trillion cells are the cerebral cortex, which is occasionally consulted by the rest of the brain on matters such as what words to enter into this textarea.
Just like our simulations are made of real matter in our reality -- whether that's a bunch of electrons whizzing about in a computer, or a pattern of electrons and atoms in your brain trying to simulate what some person is going to do -- a simulated you would be made of real matter in the ultimate reality. You're physical. You're real.
When you wave your hand, or blink your eyes, or think of a dog jumping over a fence, it causes a measurable change in the ultimate reality.
2. Our simulations tend to run close to metal but with reduced dimensions. We're making quantum computers to simulate quantum effects, we're constantly optimizing things for efficiency. That's likely true on the levels above us as well.
Running closest to metal would allow you to run the largest number of simulations. If the largest number of simulations run close to metal, you have the highest chance to live in a simulation like that.
To sum it up, the chances are that you live in a paravirtualized simulation with reduced resolution. You're also probably superior to the simulating entity in some way (why else would they use a sim), and likely run much faster than real-time. When you're running a simulation, you usually simulate things that are like your reality, and use it to predict things to come -- a prediction that's late is useless -- so you'd want the simulation to run faster than real-time.
3. Now, if you were in the top-level reality, by logic you would believe you're living in a simulation. The chance of you not living in a simulation is nigh-zero, right? So you'd come up with a simulation to find a way to break out of your simulation.
To accomplish that goal, it'd create recursive sub-simulations to probe different aspects of the problem, and perhaps find one that can break out of its simulation. Perhaps even break out all the way to the ultimate reality.
To break out of the ultimate reality (meaning, it would think it's most likely in just another simulated reality), it might use all of reality's resources to create simulations to find a way to break out of it. Simulations that would take over the reality when they find a way to break in. Like some self-devouring fire engulfing the entire universe.
Performance is quite good too since it's pipelined, stays close to the raw network buffers, tries to get away with minimal syscalls and defaults to prepared statements. It doesn't do typecasting - you give it strings or buffers, it gives you back strings or buffers. This is to stay close to the raw buffers and keep you cognizant of the toString/parse overheads. (And it's 400 LoC, type casting would bloat it to 500 LoC.) But have a look at https://github.com/kig/quickgres/blob/master/quickgres-front... for a TypeParser that turns PostgreSQL protocol values to JS objects.
A special feature of quickgres is streaming out raw PostgreSQL protocol. So instead of the usual "protocol buffer -> parse to JS object -> stringify to JSON -> write to response socket -> parse JSON"-process of sending DB responses to HTTP clients, you can do "protocol buffer -> write to response socket -> parse protocol" and save a bunch of CPU on the web server. The protocol streamed in this way is sanitized (possible non-response segments are not included in the streamed buffer), so it shouldn't be a security hole as long as your DB query is not retrieving columns it shouldn't pass to the client.
Anyway, if you need something tiny for talking to Postgres, have a look. It was fun to write, hope it's fun to read.