conv.

All stories
TechQuiet 11d · day 13

Serce explains why whitespace detection is deceptively complex

A deep dive into why checking for whitespace isn't as simple as comparing a character to a space.

What to know

  • Whitespace detection is far more complex than checking for a space character—Unicode defines 25 whitespace characters with different purposes and visual properties.
  • Major programming runtimes (Java, Python, JavaScript) implement conflicting definitions of whitespace, creating interoperability challenges and potential bugs.
  • Even characters named 'space' can look empty or not, and some contain the word 'space' but aren't whitespace characters at all, making intuitive classification unreliable.

Serce Developer and author

Serce explains why whitespace detection is deceptively complex
java,performance

How it unfolded 2 developments, newest first · click a bar or a number to jump posts

Peak 3 pieces in 3h at Oct 30, 5 PM; 21 pieces over 13 days (7 posts · 14 comments) Oct 30, 5 PM — 3 pieces · 2 posts · 1 comment — Lobsters 2, Reddit 1Oct 30, 8 PM — 1 piece · 1 comment — Lobsters 1Oct 30, 11 PM — 1 piece · 1 post — Hacker News 1Oct 31, 2 AM — 1 piece · 1 comment — Lobsters 1Oct 31, 5 AM — 2 pieces · 2 comments — Lobsters 2Oct 31, 8 AM — quietOct 31, 11 AM — 3 pieces · 1 post · 2 comments — Lobsters 2, Hacker News 1Oct 31, 2 PM — 2 pieces · 2 comments — Lobsters 2Oct 31, 5 PM — 1 piece · 1 comment — Lobsters 1Oct 31, 8 PM — 1 piece · 1 comment — Lobsters 1Oct 31, 11 PM — quietNov 1, 1 AM — quietNov 1, 4 AM — 2 pieces · 1 post · 1 comment — Hacker News 1, Lobsters 1Nov 1, 7 AM — quietNov 1, 10 AM — 1 piece · 1 comment — Lobsters 1Nov 1, 1 PM — 1 piece · 1 comment — Lobsters 1Nov 1, 4 PM — quietNov 1, 7 PM — quietNov 1, 10 PM — quietNov 2, 1 AM — quietNov 2, 4 AM — 1 piece · 1 post — Hacker News 1Nov 2, 7 AM — quietNov 2, 10 AM — quietNov 2, 1 PM — quietNov 2, 4 PM — quietNov 2, 7 PM — quietNov 2, 10 PM — quietNov 3, 1 AM — quietNov 3, 4 AM — quietNov 3, 7 AM — quietNov 3, 10 AM — quietNov 3, 1 PM — quietNov 3, 4 PM — quietNov 3, 7 PM — quietNov 3, 10 PM — quietNov 4, 1 AM — quietNov 4, 4 AM — quietNov 4, 7 AM — quietNov 4, 10 AM — quietNov 4, 1 PM — quietNov 4, 4 PM — quietNov 4, 7 PM — quietNov 4, 10 PM — quietNov 5, 1 AM — quietNov 5, 4 AM — quietNov 5, 7 AM — quietNov 5, 10 AM — quietNov 5, 1 PM — quietNov 5, 4 PM — quietNov 5, 7 PM — quietNov 5, 10 PM — quietNov 6, 1 AM — quietNov 6, 4 AM — quietNov 6, 7 AM — 1 piece · 1 post — Hacker News 1Nov 6, 10 AM — quietNov 6, 1 PM — quietNov 6, 4 PM — quietNov 6, 7 PM — quietNov 6, 10 PM — quietNov 7, 1 AM — quietNov 7, 4 AM — quietNov 7, 7 AM — quietNov 7, 10 AM — quietNov 7, 1 PM — quietNov 7, 4 PM — quietNov 7, 7 PM — quietNov 7, 10 PM — quietNov 8, 1 AM — quietNov 8, 4 AM — quietNov 8, 7 AM — quietNov 8, 10 AM — quietNov 8, 1 PM — quietNov 8, 4 PM — quietNov 8, 7 PM — quietNov 8, 10 PM — quietNov 9, 1 AM — quietNov 9, 4 AM — quietNov 9, 7 AM — quietNov 9, 10 AM — quietNov 9, 1 PM — quietNov 9, 4 PM — quietNov 9, 7 PM — quietNov 9, 10 PM — quietNov 10, 1 AM — quietNov 10, 4 AM — quietNov 10, 7 AM — quietNov 10, 10 AM — quietNov 10, 1 PM — quietNov 10, 4 PM — quietNov 10, 7 PM — quietNov 10, 10 PM — quietYesterday, 1 AM — quietYesterday, 4 AM — quietYesterday, 7 AM — quietYesterday, 10 AM — quietYesterday, 1 PM — quietYesterday, 4 PM — quietYesterday, 7 PM — quietYesterday, 10 PM — quietToday, 1 AM — quietToday, 4 AM — quietToday, 7 AM — quietToday, 10 AM — quietToday, 1 PM — quietToday, 4 PM — quietToday, 7 PM — quiet 1–2
Oct 31Nov 1Nov 2Nov 3Nov 4Nov 5Nov 6Nov 7Nov 8Nov 9Nov 10yesterdaynow · 8:28 PM ET
  1. 1

    Article explains why Unicode whitespace definition matters

    The piece notes that Unicode's White_Space property includes 25 characters, each serving distinct purposes—figure space for table digits, thin and hair space for variable gaps, no-break space for line-wrap control, and even OGHAM SPACE MARK that can render as a visible line in certain fonts.

    “Yet the code looks a lot more complex than a simple c == ' ' check.”
    — Serce, Author · source
    • Perfect hashing is ready cute! The implementation is very small and simple even though it's very fast: it's just the proof that it does actually work which is complicated. :D

      0x2ba22e11java,performance13d ago6▲view on Lobsters ↗
    2 more of the top 3 · 14 posts in this stretch
    • > What adds more complexity is that Unicode is not frozen in time, and is constantly evolving. And this affects the definition of whitespace. For example, Unicode 6.3 had reclassified MONGOLIAN VOWEL SEPARATOR (U+180E) from a space separator to a format character, removing its White_Space property. The Unicode whitespace set had changed from 26…

      doug-moenjava,performance12d ago4▲view on Lobsters ↗
    • I think it helps to have an intuition for how high-performance multipliers work to sanity check numbers like that. Here's my hand-wavy intuition for why the 3 logical stages map to roughly 3 cycles of latency in high performance implementations. If you look at industry papers on multipliers you'll see that it's not _too_ far from the truth…

      pervognsenjava,performance11d ago3▲view on Lobsters ↗
    all of them →
  2. background

    Article details how runtimes disagree on whitespace definitions — The analysis reveals that Java excludes no-break space (U+00A0) from its whitespace set, while Python includes it and also recognizes 29 characters total. JavaScript uses yet another approach with regex character classes, each runtime implementing its own definition rather than following a single standard.

  3. 2

    Serce publishes analysis of whitespace detection complexity

    A developer published an article examining the Guava library's whitespace-checking method from Google, exploring why the code is far more complex than a simple space check. The piece traces the problem to Unicode's definition of 25 whitespace characters and conflicting implementations across runtimes.

    “Yet the code looks a lot more complex than a simple c == ' ' check. This made me curious and sent me down a small rabbit hole…”
    — Serce

What people are saying 11 voices from 1 site · best of 14 · verbatim