Readit News logoReadit News
pjscott commented on Programming language speed comparison using Leibniz formula for π   niklas-heer.github.io/spe... · Posted by u/PKop
gavinray · a day ago
I'm fairly sure I can speed the JVM implementations up a significant amount by MMAP'ing the file into memory and ensuring it's aligned.
pjscott · a day ago
I'm not too familiar with the JVM so perhaps I'm missing something here: how would that help? The file is tiny, just a few bytes, so I'd expect the main slowdown to come from system call overhead. With non-mmap file I/O you've got the open/read/close trio, and only one read(2) should be needed, so that's three expensive trips into kernel space. With mmap, you've got open/stat/mmap/munmap/close.

Memory-mapped I/O can be great in some circumstances, but a one-time read of a small file is one of the canonical examples for when it isn't worth the hassle and setup/teardown overhead.

pjscott commented on Programming language speed comparison using Leibniz formula for π   niklas-heer.github.io/spe... · Posted by u/PKop
systems · a day ago
why is ocaml so low, didnt expect this
pjscott · a day ago
As with all the ahead-of-time compiled languages that I checked, the answer is that it generates non-SIMD code for the hot loop. The assembly code I see in godbolt.org isn't bad at all; the compiler just didn't do anything super clever.
pjscott commented on Programming language speed comparison using Leibniz formula for π   niklas-heer.github.io/spe... · Posted by u/PKop
klaff · a day ago
I think I get why C++ thru C are all similar (all compile to similar assembly?), but I don't get why Go thru maybe Racket are all in what looks like a pretty narrow clump. Is there a common element there?
pjscott · a day ago
The common element is that they're written with the most obvious version of the code, while the ones in the faster bucket are either explicitly vectorized or written in non-obvious ways to help the compiler auto-vectorize. For example, consider the Objective C version of the loop in leibniz.m:

  for (long i = 2; i <= rounds + 2; i++) {
      x *= -1.0;
      pi += x / (2.0 * i - 1.0);
  }
With my older version of Clang, the resulting assembly at -O3 isn't vectorized. Now look at the C version in leibniz.c:

  rounds += 2u; // do this outside the loop
  for (unsigned i=2u; i < rounds; ++i) // use ++i instead of i++
  {
      double x = -1.0 + 2.0 * (i & 0x1); // allows vectorization
      pi += (x / (2u * i - 1u)); // double / unsigned = double
  }
This produces vectorized code when I compile it. When I replace the Objective C loop with that code, the compiler also produces vectorized code.

You see something similar in the other kings-of-speed languages. Zig? It's the C code ported directly to a different syntax. D? Exact same. Fortran 90? Slightly different, but still obviously written with compiler vectorization in mind.

(For what it's worth, the trunk version of Clang is able to auto-vectorize either version of the loop without help.)

pjscott commented on Programming language speed comparison using Leibniz formula for π   niklas-heer.github.io/spe... · Posted by u/PKop
ajross · a day ago
It's an extremely simple algorithm, just one loop with an iterated expression inside it. You can check the source code at: https://github.com/niklas-heer/speed-comparison/tree/master/...

It's true this is a microbenchmark and not super informative about "Big Problems" (because nothing is). But it absolutely shows up code generation and interpretation performance in an interesting way.

Note in particular the huge delta between rust 1.92 and nightly. I'm gonna guess that's down to the autovectorizer having a hole that the implementation slipped through, and they fixed it.

pjscott · a day ago
The delta there is because the Rust 1.92 version uses the straightforward iterative code and the 1.94-nightly version explicitly uses std::simd vectorization. Compare the source code:

https://github.com/niklas-heer/speed-comparison/blob/master/...

https://github.com/niklas-heer/speed-comparison/blob/master/...

pjscott commented on UK House of Lords attempting to ban use of VPNs by anyone under 16   alecmuffett.com/article/1... · Posted by u/nvarsj
tehjoker · 9 days ago
It's crazy that there is a house of unelected lords in an allegedly modern country.
pjscott · 9 days ago
They have very limited power these days. They advise the House of Commons, as more or less a hereditary think tank. They can delay the passage of bills, though this has been limited to a maximum delay of one year since 1949 (less for some types of bills) and there are some checks on this ability. They have a few other things they can do that are (IMO) too boring to warrant much thought unless you're a member of parliament.

The idea of a House of Lords does strike me as a bit odd, but it's not really the big deal it used to be.

pjscott commented on JIT: So you want to be faster than an interpreter on modern CPUs   pinaraf.info/2025/10/jit-... · Posted by u/pinaraf
klipklop · 2 months ago
A shame operating systems like iOS/iPadOS do not allow JIT. iPad Pro's have such fast CPU's that you cant even use fully because of decisions like this.
pjscott · 2 months ago
They do, technically, allow JIT. You need a very hard-to-obtain entitlement that lets you turn writable pages into executable read-only pages, and good luck getting that entitlement if (for some reason) your name isn’t “mobilesafari”, but the capability exists.
pjscott commented on Low Earth Orbit Visualization   platform.leolabs.space/vi... · Posted by u/handfuloflight
pjscott · 3 months ago
It may comfort you to hear that the Starlink satellites are tiny in comparison to the vastness of their orbit – the visualization makes them appear larger than they are, so you can see them clearly – and that they’re low enough that they’ll naturally de-orbit and burn up in the atmosphere after about 15 years even without using their maneuvering thrusters.

They’re providing worldwide rural broadband, and according to the FAA they’re doing so in a way that’s careful and responsible about space debris and collision avoidance. Is disgust truly warranted in this case?

pjscott commented on How to Network as an Introvert   aginfer.bearblog.dev/how-... · Posted by u/agcat
1shooner · 5 months ago
I consider myself an introvert, and this article seems like an impossible anxiety spiral-inducing checklist.

>Don’t waste their time with “Great party.” Say something more vivid. “The lighting is perfect.”

What? I think someone needing this level of instruction would be better served by basic mindfulness and small, manageable exercises in active listening or empathetic dialog, rather than a grab bag of non-contextual tips like this.

pjscott · 5 months ago
I’m also introverted, and I also found this article overwhelming – if I tried to do it all at once, which seems so laughably unrealistic for me that I just wouldn’t try. Instead, probably the best way to read this is as something to approach gradually. Try just one thing on the list, or two if you’re feeling ambitious. Go for a delta that you can manage. And see if it’s working for you, because often the advice that works wonders for one person completely falls flat for another.

(On a slightly funny personal note, the thing that helped me most with social skills was watching the first few seasons of Buffy the Vampire Slayer in my first year of college. The actors emoted so clearly that even I could understand what feelings they were trying to convey, and that’s how I learned to do body language and appropriate vocal tones. This took me from unapproachable to merely awkward, a huge step up in the world.)

pjscott commented on Guess I'm a rationalist now   scottaaronson.blog/?p=890... · Posted by u/nsoonhui
mkoubaa · 6 months ago
The problem with rationalism is we don't have language to express our thoughts formally enough nor a compiler to transform that language into something runnable (platonic AST) nor a machine capable of emulating reality.

Expecting rational thought to correspond to reality is like expecting a 6 million line program written in a hypothetical programming language invented in the 1700s to run bug free on a turing machine.

Tooling matters.

pjscott · 6 months ago
The rationalist movement has been talking about this since the beginning, and has consistently come to the conclusion that of course the thing to do is admit to our own fallibility and try to do the best we can with our profound limitations.

(You didn’t explicitly say otherwise, so if my exasperation is misdirected then you have my apology in advance.)

pjscott commented on Guess I'm a rationalist now   scottaaronson.blog/?p=890... · Posted by u/nsoonhui
jrm4 · 6 months ago
looks like I riled up the Rationalists, huh
pjscott · 6 months ago
You stated one of their core doctrines, something they’ve been loudly preaching for as long as they’ve existed, as though it was something they disagree with and had never even considered. Can you blame them for a bit of exasperation? For wanting to simply downvote-and-disengage from someone who makes up falsehoods about them and then gloats about how it annoyed them? Life is too short to tilt at windmills.

u/pjscott

KarmaCake day9732May 23, 2010View Original