Skip to content
HomeVideosBooksBlogs
AllTop postsTopics
Podcasts
HistoryListsWatch laterLiked videosFollowing

The videos, books, blogs and podcasts Hacker News keeps recommending, all in one place.

VideosBooksBlogsPodcastsAboutPrivacySettings

Data from Hacker News, HackerTube, HackerBooks, HackerBlogs and Open Library. Credits · Not affiliated with Y Combinator.

HomeVideosBooksBlogsPodcasts
Ctrl K
    P

    Pavel Zemtsov

    pzemtsov.github.io · Personal blog · on HN since 2014

    Pavel Zemtsov writes technical posts on performance and low-level bugs in Java, C, and C++, such as alignment, hashing, and timing.

    Visit blogHN submissions
    Systems & PerformanceProgramming
    What HN says

    HN commenters cite his posts as concrete examples of alignment-related undefined behavior, a Game of Life implementation, and the real cost of system calls.

    Stats for nerds
    23HN people shared it
    16linked in comments
    751story points
    May 2026last shared
    2014people per year2026

    Top posts on HN

    1. 1
      The slow currentTimeMillis()
      4 people · 326 points · first shared 2017 · 52 comments on HN
    2. 2
      A bug story: data alignment on x86
      9 people · 325 points · first shared 2016 · 107 comments on HN
    3. 3
      Abnormal String Hashing
      1 person · 52 points · first shared 2019 · 15 comments on HN
    4. 4
      Game of Life, hash tables and hash codes
      2 people · 34 points · first shared 2015 · Discussion on HN
    5. 5
      Building a fast queue between C++ and Java
      2 people · 3 points · first shared 2018 · Discussion on HN
    6. 6
      Statistical variables in Java: not quite legal but very fast
      1 person · 3 points · first shared 2017 · Discussion on HN
    7. 7
      Making a fast char searcher in C
      1 person · 3 points · first shared 2019 · Discussion on HN
    8. 8
      Home-made hash tables in Java
      1 person · 2 points · first shared 2016 · Discussion on HN
    9. 9
      Searching for a Better IndexOf
      1 person · 1 points · first shared 2019 · Discussion on HN
    10. 10
      Searching in a constant set using conflict-free hashing
      1 person · 1 points · first shared 2016 · Discussion on HN

    What HN people wrote when they linked it

    • exikyutSep 2018

      > 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 anytime soon.

      Here's how I see it. I believe that unification, specifically within software, is universally based on the idea that we can clean up the world (where "the world" refers to a given software environment) if only we can reimagine it clearly enough and, to borrow a few technical concepts, compute a delta with enough detail and resolution that it'll carry us from where we are to where we want to be. (With the implicit [mis]understanding that all we need to do is make said delta exist, and then it'll do all the work of carrying us.)

      I think the above is what we're trying to do - and that we're doing it because we're staring at/barking up the wrong set of trees (the associated forests of which got lost long ago).

      Ultimately, the world is a disorganized mess. Any security researcher could entertain you for days with highly-detailed hair-raising examples and proofs of this. I've very recently (finally) realized this is because, at a very high level, the world operates somewhat similarly to the bazaar model Linux uses. Evolution is highly organic, often…

    • Dylan16807Oct 2017

      > 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 that every one of these loads will be exactly 4 bytes apart. Even worse, it might know that int32_t allocations will always be aligned, so it will assume that every load will be 4-byte-aligned. It then might output code that loses track of the bottom two bits, or SSE instructions that only work with certain alignments.

      This isn't theoretical, this exact kind of bug has happened before, on a normal non-malicious compiler: http://pzemtsov.github.io/2016/11/06/bug-story-alignment-on-x86.html https://news.ycombinator.com/item?id=12889855

      It's true that the buffer overrun issue is the same for either version; I misread what was being replaced. But the alignment issue is specific to this version, and can't be ignored.

    • AsookaMay 2019

      Oh 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] +
      someListOfNumbers[3];

      If headerOffset is not a multiple of 4, bad things will happen. On x86 you'll get away with it... Unless you were summing many more ints and the compiler decides to use aligned SSE loads for speed[1]. On ARM you'll get a SIGBUS just for trying to read unaligned ints (IIRC). You can fix that by wrapping your ints or whatever you're trying to read in a packed struct, but it is yet another thing to keep in mind.

      [1] http://pzemtsov.github.io/2016/11/06/bug-story-alignment-on-x86.html

    • ambrop7Jan 2018

      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-currenttimemillis.html ("Off-topic: A system call"). But they will be slow with this mitigation.

    • oconnor663Nov 2018

      > 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-x86.html

    • dleskovJul 2014

      > 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-as-java.html

    Related

    Probably Danceprobablydance.com74 people

    Fibonacci Hashing: The Optimization That the World Forgot

    Probably Dance
    Personal · last shared 2026
    Ralf Jungralfj.de99 people

    There is no memory safety without thread safety

    Ralf Jung
    Personal · last shared 2026
    Herb Suttergotw.ca84 people

    Ritchie, Stroustrup, and Gosling interview

    Herb Sutter
    Personal · last shared 2026
    Andrzej's C++ blogakrzemi1.wordpress.com35 people

    A bug in GCC that may cause memory leaks in valid C++ programs

    Andrzej's C++ blog
    Personal · last shared 2025
    matkladmatklad.github.io237 people

    Architecture.md

    matklad
    Personal · last shared 2026
    Martin Sústrik250bpm.com126 people

    Why should I have written ZeroMQ in C, not C++

    Martin Sústrik
    Personal · last shared 2026
    Emil Ernerfeldtilikebigbits.com53 people

    The Myth of RAM (2014)

    Emil Ernerfeldt
    Personal · last shared 2026
    Aras Pranckevičiusaras-p.info79 people

    I accidentally Blender VSE

    Aras Pranckevičius
    Personal · last shared 2026