Top all-time · #3304
Experiments in program optimisation ququMy blogwewe
Personal blog · pzemtsov.github.ioprogrammingsystems
Experiments in program optimisation ququMy blogwewe is a personal blog at pzemtsov.github.io about programming and systems. Since 2014, 23 different Hacker News readers have linked it 27 times, most often “A bug story: data alignment on x86”. The last post was in 2019, but the archive is still widely read.
Too few sampled comments (11) to say how often HN recommends it.?
Why HN links it
HN commenters link this blog for low-level performance and C pitfalls, especially its alignment bug story, and cite posts on syscalls, mmap, Game of Life hash tables and C-to-fast optimisation.
Summarised by Claude from a sample of 11 HN comments that link here. Each comment is marked recommending, critical or neutral (citing without judging); how this works.
Most-linked posts?
- A bug story: data alignment on x866 people · 6 mentions · first linked 2016-11-07
- A bug story: data alignment on x86 (2016)4 people · 4 mentions · first linked 2019-07-05
- The slow currentTimeMillis()3 people · 4 mentions · first linked 2017-07-24
What Hacker News says?
I think syscalls are not as slow as many people imagine they are, especially with modern CPUs and kernels (there are special instruction for syscalls that are faster than the old "interrupt" approach). See here: http://pzemtsov.github.io/2017/07/23/the-slow-currenttimemil... ("Off-topic: A system call"). But they will be slow with this mitigation.
Comment linking /2017/07/23/the-slow-currenttimemillis.html
on “Linux page table isolation is not needed on AMD processors”Submitted The slow currentTimeMillis() as a story · 323 points
HN discussionOh I see you didn't get to caveat 5: you can't read anything more complicated than raw bytes, i.e. chars, because of unaligned memory access errors. Let's say you mmap a file and do something like this: char *fileContents=...mmap etc...; int headerOffset=*(int*)fileContents; int *someListOfNumbers=(int*)(fileContents+headerOffset); int importantSum= someListOfNumbers[0] + someListOfNumbers[1] + someListOfNumbers[2]…
Comment linking /2016/11/06/bug-story-alignment-on-x86.html
on “Use mmap with care”Submitted A bug story: data alignment on x86 as a story · 151 points
HN discussionDid you consider something like the following to speed up the calculation? This method can go forward _really_ fast. Not sur e if it can also go backward... https://pzemtsov.github.io/2015/04/24/game-of-life-hash-tabl...
Comment linking /2015/04/24/game-of-life-hash-tables-and-hash-codes.html
on “Finding Mona Lisa in the Game of Life”Submitted A bug story: data alignment in C on x86 (2016) as a story · 134 points
HN discussionI believe the article was http://pzemtsov.github.io/2017/07/23/the-slow-currenttimemil... Although I couldn't easily find it in my history or on HN. I had to resort to the Googles.
Comment linking /2017/07/23/the-slow-currenttimemillis.html
on “How I implemented my own crypto”Submitted Abnormal String Hashing as a story · 52 points
HN discussion> I am often mystified when people say C is "hard" Here are some examples of why people say C is hard: https://pzemtsov.github.io/2016/11/06/bug-story-alignment-on... https://blog.regehr.org/archives/1520 https://www.imperialviolet.org/2016/06/26/nonnull.html
Comment linking /2016/11/06/bug-story-alignment-on-x86.html
on “D as a C Replacement”Submitted A bug story: data alignment on x86 (2016) as a story · 40 points
HN discussion> Optimizers don't look for undefined behaviour to then do whatever, they look for the set of defined behaviours and then try to generate the cheapest code that behaves correctly in all those cases--and if that means that undefined cases do weird stuff, that's an acceptable side effect. > if any of the bytes are not inside any valid C object, then that would produce undefined behaviour The compiler might also assume…
Comment linking /2016/11/06/bug-story-alignment-on-x86.html
on “A Branchless UTF-8 Decoder”Submitted Game of Life, hash tables and hash codes as a story · 34 points
HN discussion> creating a super-optimized tight loop of a program in C++, C or (better) assembly might be much easier to do than in higher level JITted languages Sometimes, the situation is exactly opposite, though: http://pzemtsov.github.io/2014/05/15/how-to-make-C-as-fast-a...
Comment linking /2014/05/15/how-to-make-C-as-fast-as-java.html
on “Java vs. Scala: Divided We Fail”Submitted Making a fast char searcher in C as a story · 3 points
HN discussion> I like the idea of software, libraries and application code all being accessible to each other and have the ability to call each other. Too much functionality is siloed behind application A or B, and the interface exposed by these applications is often woefully inadequate for anything interesting. Maybe I'm skeptical, but I've gotten to the point where I believe that this specific problem is not going to be solved…
Comment linking /2016/11/06/bug-story-alignment-on-x86.html
on “The Early History Of Smalltalk (1993)”Submitted Statistical variables in Java: not quite legal but very fast as a story · 3 points
HN discussion> A compiled binary that worked correctly won't suddenly run into undefined behaviour, that can only happen if you upgrade compiler versions... Upgrading the compiler version and causing undefined behavior sounds pretty sudden. Here's my favorite story along those lines: http://pzemtsov.github.io/2016/11/06/bug-story-alignment-on-...
Comment linking /2016/11/06/bug-story-alignment-on-x86.html
on “A Guide to Undefined Behavior in C and C++ (2010)”Submitted Building a fast queue between C++ and Java as a story · 2 points
HN discussionInterestingly enough, I've just checked the code from this article ( https://pzemtsov.github.io/2016/11/06/bug-story-alignment-on... ), linked by the OP's article, and guess what - CLANG generates code that does not crash, although it still uses SSE4.
Comment linking /2016/11/06/bug-story-alignment-on-x86.html
on “GCC always assumes aligned pointer accesses”Submitted The slow currentTimeMillis() as a story · 2 points
HN discussionA concrete example of undefined behavior caused by an unaligned pointer: https://pzemtsov.github.io/2016/11/06/bug-story-alignment-on...
Comment linking /2016/11/06/bug-story-alignment-on-x86.html
on “Everything in C is undefined behavior”Submitted Home-made hash tables in Java as a story · 2 points
HN discussionSubmitted Demultiplexing of E1 Streams as a story · 1 points
HN discussionSubmitted Building a fast queue between C++ and Java (2018) as a story · 1 points
HN discussionSubmitted Searching for a Better IndexOf as a story · 1 points
HN discussionSubmitted The slow currentTimeMillis() as a story · 1 points
HN discussionSubmitted Searching in a constant set using conflict-free hashing as a story · 1 points
HN discussion