HNHacker News
TopNewBestAskShowJobs

shwestrick

343 karma · joined August 12, 2020

submissionscomments
shwestrick··on Reference count, don't garbage collect
This debate has gone round and round for decades. There are no hard lines; this is about performance tradeoffs, and always will be.

Perhaps the biggest misconception about reference counting is that people believe it avoids GC pauses. That's not true. Essentially, whereas tracing GC has pauses while tracing live data, reference counting has pauses while tracing garbage.

Reference counting is really just another kind of GC. I'd highly recommend perusing this paper for more details: A Unifying Theory of Garbage Collection. https://web.eecs.umich.edu/~weimerw/2012-4610/reading/bacon-...

One of the biggest issues with reference counting, from a performance perspective, is that it turns reads into writes: if you read a heap-object out of a data structure, you have to increment the object's reference count. Modern memory architectures have much higher read bandwidth than write bandwidth, so reference counting typically has much lower throughput than tracing GC does.

shwestrick··on How side effects work in FP
I think laziness would be a distraction here. The idea of encoding effects as "action values" is relevant and interesting, even under eager evaluation.

Certainly laziness has influenced a lot of things in the world of FP. But it's really helpful to distinguish laziness from FP, especially considering the problems that laziness introduces.

shwestrick··on Failing to Learn Zig via Advent of Code
OCaml is pretty close already to what you're describing. The OCaml ecosystem fully embraces imperative programming. And if the syntax of OCaml is problematic, then perhaps ReasonML (https://reasonml.github.io/) is what you're looking for: a curly-braces syntax for OCaml.
shwestrick··on Provably space-efficient parallel functional programming
A combination of both. This work targets multicore, but execution on the GPU is definitely possible. It's just a different line of research. I'd highly recommend taking a look at Futhark (https://futhark-lang.org/), which has a similar programming model (purely functional and parallel), but targets GPU. The compilation strategy is quite a bit different!
shwestrick··on Provably space-efficient parallel functional programming
Author here. One of the cool things about the property we're using here---disentanglement---is that it specifically allows for shared data, under only mild restrictions. This allows us, for example, to implement fast libraries which utilize shared mutable state for efficiency under the hood. A good example is our parallel arrays library (https://github.com/shwestrick/sml-parseq), which is "purely functional" in terms of its interface, but not its implementation.

It's helpful here to distinguish parallelism from concurrency. Disentanglement naturally emerges in data-race-free parallel programs, which have no concurrency. But certainly, you bring up a good point for programs that are highly concurrent in addition to being highly parallel. There's lots of work already on concurrent functional programming, for example CML (https://en.wikipedia.org/wiki/Concurrent_ML), and we think these ideas could be adapted to work with disentanglement really well.

shwestrick··on Effective Concurrency with Algebraic Effects in Multicore OCaml
The defining feature of these effect systems is "resumable continuations". Essentially, at the point where you catch an exception, you have the option of resuming the code which threw the exception, and you can tell it how to proceed.

So, whereas exceptions only jump backwards in the stack, resuming a continuation sorta lets you jump forwards again, back to where you were. It's really powerful stuff.

shwestrick··on Tiny Treeshaker: JavaScript tree shaking in 200 lines of code
"opposite" is not the right term... tree-shaking appears to be a particular technique for dead code elimination.

I.e., there are many algorithms you could use to eliminate dead code, and tree-shaking seems to just be a simple one that works well for JS.

shwestrick··on AMD vs. Intel CPU Market Share
There's a lot of caveats on this data. It's only showing the ratio of people submitting reports through their benchmark software, which apparently only runs on Windows. So, that makes it sound like the entire space of Linux servers is excluded.

I'm just speculating here, but it feels to me like they're just not accurately measuring the market share for servers.

shwestrick··on Rust meets the web – a clash of programming paradigms (2020)
In the "Race Conditions? Not with Javascript!" section:

> They [...] decided that no concurrency between threads is allowed, for the safety of everybody. This resolves the race conditions by removing the possibility that multiple threads ever run at the same time.

Nope! It's very easy to write a JS program with a race condition. Like this one, which sometimes outputs 0, sometimes 1:

    var a = 0;
    setTimeout(function() { a = 1; }, 50);
    setTimeout(function() { console.log(a); }, 49);
shwestrick··on A 'Bubble Barrier' is trapping plastic waste before it can get into the sea
Genius! Cheap, effective, and low-maintenance.
shwestrick··on Basic Music Theory in ~200 Lines of Python
I don't think this is really anything to do with music vs programming. The author just used the wrong words... it's pretty clear they meant "generate a chromatic scale starting at any note" ;)

Thanks for bringing up the connection with symmetric scales -- these are really interesting!

shwestrick··on Can continuation passing style code perform well?
An observation that I find kinda nice: passing a default value is essentially just a special case of CPS :)
shwestrick··on How to Write Readable Code
> you should always return in an 'if' branch

Interesting. This code style simply doesn't need 'else' at all. I can surely say, if I was reading a codebase that adhered to this discipline, it would be very easy to read.

What are your thoughts on how difficult it is to write code in this style?

shwestrick··on Safe dead code removal in a pure functional language
IMO one of the most valuable things I've learned about static analysis is that the halting problem is overly pessimistic. It's easy to prove very interesting things about real-world code.

Things like dead-code removal are a pretty standard for modern optimizing compilers!

shwestrick··on Myopia treatment 'smart glasses' from Japan to be sold in Asia
Some additional information here: https://www.kubotaholdings.co.jp/en/ir/docs/20201216_EN_eSpe...

Assuming this device is actually legit (I'm skeptical...), it would need e.g. FDA approval to be used in the USA, correct?

shwestrick··on Europe Is Guaranteeing Citizens the Right to Repair
I think you and @stretchcat are saying the same thing. Ease-of-repair and durability are more important than recycling.
shwestrick··on Filling the Void of a Physical Whiteboard
I love this. It's so easy to use and works great on a trackpad. I'm going to start using it in my meetings.

Nice job!

------

EDIT: After playing with it for a bit, I have some feedback :)

- Sometimes, I accidentally press Z instead of shift, or vice versa. I would love to have undo! Backspace or delete hotkey would be perfect.

- For selecting colors, it would be great to just be able to press 1,2,3,4 (rather than cycling through).

- I often forget what color I have selected. Perhaps the cursor could be colored to indicate this?

- When typing text, my first instinct was to use the arrow keys to move the cursor around, but this doesn't work. Also, it's hard to select where the cursor should go to edit.

- The shift and Z hotkeys are great. But I don't quite understand selecting the tools. If I can just hold down Z to erase, why would I ever select the eraser tool? It seems like the most efficient approach is to only ever have the text tool selected, so that at any time I can click to create text, but otherwise I use Z/shift to draw.

shwestrick··on Hexagonal Grids (2013)
Such an invaluable resource! I spent many hours here while helping develop https://hexiconapp.com/. The axial coordinate system, in particular, makes working with hexagons much simpler.
shwestrick··on The Origin of the Shell
Apparently RUNCOM is where the "rc" naming convention comes from?? (E.g. bashrc, vimrc, ...) Very cool. I always wondered what the "rc" meant.

https://en.wikipedia.org/wiki/Run_commands

shwestrick··on Scipio: A Thread-per-Core Crate for Rust and Linux
Hmm I was separating the concept of "thread-per-core" from sharding. I would argue that typical cooperative task schedulers (e.g. work-stealing) get the performance benefits of thread-per-core without requiring any static partitioning.

But if thread-per-core is fundamentally tied to the idea of sharding, then I think I see what you're saying.

shwestrick··on Scipio: A Thread-per-Core Crate for Rust and Linux
Thread-per-core has been around for a while! It's how a lot of modern multicore languages work. You've probably heard of "green" or "lightweight" threads before... it's all the same idea. Typically, you'd want to use a scheduler (probably work-stealing https://en.wikipedia.org/wiki/Work_stealing) under the hood to dynamically assign tasks to processors, which is much more effective at load-balancing than "sharding".

All of these languages/libraries use a dynamic scheduler for load-balancing:

* Rayon (Rust) [https://github.com/rayon-rs/rayon]

* Goroutines (Go) [https://golangbyexample.com/goroutines-golang/]

* OpenMP [https://www.openmp.org/]

* Task Parallel Library (.NET) [https://docs.microsoft.com/en-us/dotnet/standard/parallel-pr...]

* Thread Building Blocks (C++) [https://software.intel.com/content/www/us/en/develop/tools/t...]

* Cilk (C/C++) [http://cilk.mit.edu/]

* Java Fork-Join and Parallel Streams [https://docs.oracle.com/javase/tutorial/collections/streams/...]

* ParlayLib (C++) [https://github.com/cmuparlay/parlaylib]

shwestrick··on Principles of Data Oriented Programming
What do you mean by "functions are supposed to be mutable"?

Perhaps you are just pointing out that the output of the function (and therefore the value of the field...?) will change as the input changes?

If mathematical tuples are immutable, then surely mathematical functions are immutable as well ;)

← PreviousPage 2 of 2