Most active commenters
  • ashvardanian(7)
  • mgaunard(4)
  • stingraycharles(3)

85 points ashvardanian | 42 comments | | HN request time: 1.673s | source | bottom
1. andersa ◴[] No.46287769[source]
From a German user perspective, ICU and your fancy library are incorrect, actually. Mass is not a different casing of Maß, they are different characters. Google likely changed this because it didn't do what users wanted.
replies(5): >>46287929 #>>46288240 #>>46288242 #>>46288366 #>>46288467 #
2. mgaunard ◴[] No.46287778[source]
In practice you should always normalize your Unicode data, then all you need to do is memcmp + boundary check.

Interestingly enough this library doesn't provide grapheme cluster tokenization and/or boundary checking which is one of the most useful primitive for this.

replies(2): >>46287938 #>>46287993 #
3. b2ccb2 ◴[] No.46287929[source]
The confusion likely stems from the relatively new introduction of the capitalized ẞ https://de.wikipedia.org/wiki/Gro%C3%9Fes_%C3%9F

Maß capitalized (used to be) MASS.

Funnily enough, Mass means one liter beer (think Oktoberfest).

replies(2): >>46288188 #>>46288190 #
4. stingraycharles ◴[] No.46287938[source]
That’s not practical in many situations, as the normalization alone may very well be more expensive than the search.

If you’re in control of all data representations in your entire stack, then yes of course, but that’s hardly ever the case and different tradeoffs are made at different times (eg storage in UTF-8 because of efficiency, but in-memory representation in UTF-32 because of speed).

replies(1): >>46288010 #
5. orthoxerox ◴[] No.46287993[source]
In practice the data is not always yours to normalize. You're not going to case-fold your library, but you still want to be able to search it.
6. mgaunard ◴[] No.46288010{3}[source]
That doesn't make sense; the search is doing on-the-fly normalization as part of its algorithm, so it cannot be faster than normalization alone.
replies(3): >>46288133 #>>46288181 #>>46288218 #
7. stingraycharles ◴[] No.46288133{4}[source]
It can, because of how CPUs work with registers and hot code paths and all that.

First normalizing everything and then comparing normalized versions isn’t as fast.

And it also enables “stopping early” when a match has been found / not found, you may not actually have to convert everything.

replies(1): >>46288760 #
8. orthoxerox ◴[] No.46288136[source]
Is it possible to extend this to support additional transformation rules like Any-Latin;Latin-ASCII? To make it possible to find "Վարդանյան" in a haystack by searching for "vardanyan"?
replies(1): >>46288259 #
9. ashvardanian ◴[] No.46288181{4}[source]
I get why it sounds that way, but it’s not actually true.

StringZilla added full Unicode case folding in an earlier release, and had a state-of-the-art exact case-sensitive substring search for years. However, doing a full fold of the entire haystack is significantly slower than the new case-insensitive search path.

The key point is that you don’t need to fully normalize the haystack to correctly answer most substring queries. The search algorithm can rule out the vast majority of positions using cheap, SIMD-friendly probes and only apply fold logic on a very small subset of candidates.

I go into the details in the “Ideation & Challenges in Substring Search” section of the article

10. andersa ◴[] No.46288188{3}[source]
It's strange, because I would expect "maß" as the case insensitive search to match "MASS" in the search text, but "mass" should not match "Maß".
11. looperhacks ◴[] No.46288190{3}[source]
Both Maß and Mass are valid spellings for a liter of beer ;) Not to confuse it with Maß, which just means any measurement, of course.
12. Const-me ◴[] No.46288218{4}[source]
> it cannot be faster than normalization alone

Modern processors are generally computing stuff way faster than they can load and store bytes from main memory.

The code which does on the fly normalization only needs to normalize a small window. If you’re careful, you can even keep that window in registers, which have single CPU cycle access latency and ridiculously high throughput like 500GB/sec. Even if you have to store and reload, on-the-fly normalization is likely to handle tiny windows which fit in the in-core L1D cache. The access cost for L1D is like ~5 cycles of latency, and equally high throughput because many modern processors can load two 64-bytes vectors and store one vector each and every cycle.

replies(1): >>46288792 #
13. looperhacks ◴[] No.46288240[source]
MASS is allowed casing of Maß, but not the preferred casing: https://www.rechtschreibrat.com/DOX/RfdR_Amtliches-Regelwerk... Page 48
14. pjmlp ◴[] No.46288242[source]
It isn't until it is, how would you write it when ß isn't available on the keyboard?

Which is why we also have to deal with the ue, ae, oe kind of trick, also known as Ersatzschreibweise.

Then German language users from de-CH region, consider Mass the correct way.

Yeah, localization and internalization is a mess to get right.

replies(1): >>46288357 #
15. unwind ◴[] No.46288255[source]
Very cool and impressive performance.

I was worried (I find it confusing when Unicode "shadows" of normal letters exist, and those are of course also dangerous in some cases when they can be mis-interpreted for the letter they look more or less exactly like) by the article's use of U+212A (Kelvin symbol) as sample text, so I had to look it up [1].

Anyway, according to Wikipedia the dedicated symbol should not be used:

However, this is a compatibility character provided for compatibility with legacy encodings. The Unicode standard recommends using U+004B K LATIN CAPITAL LETTER K instead; that is, a normal capital K.

That was comforting, to me. :)

[1]: https://en.wikipedia.org/wiki/Kelvin#Orthography

replies(1): >>46288569 #
16. ashvardanian ◴[] No.46288259[source]
Yes — fuzzy and phonetic matching across languages is part of the roadmap. That space is still poorly standardized, so I wanted to start with something widely understood and well-defined (ICU-style transforms) before layering on more advanced behavior.

Also, as shown in the later tables, the Armenian and Georgian fast paths still have room for improvement. Before introducing higher-level APIs, I need to tighten the existing Armenian kernel and add a dedicated one for Georgian. It’s not a true bicameral script, but some characters are folding fold targets for older scripts, which currently forces too many fallbacks to the serial path.

17. xking5205 ◴[] No.46288316[source]
its good
18. ashvardanian ◴[] No.46288320[source]
This article is about the ugliest — but arguably the most important — piece of open-source software I’ve written this year. The write-up ended up long and dense, so here’s a short TL;DR:

I grouped all Unicode 17 case-folding rules and built ~3K lines of AVX-512 kernels around them to enable fully standards-compliant, case-insensitive substring search across the entire 1M+ Unicode range, operating directly on UTF-8 bytes. In practice, this is often ~50× faster than ICU, and also less wrong than most tools people rely on today—from grep-style utilities to products like Google Docs, Microsoft Excel, and VS Code.

StringZilla v4.5 is available for C99, C++11, Python 3, Rust, Swift, Go, and JavaScript. The article covers the algorithmic tradeoffs, benchmarks across 20+ Wikipedia dumps in different languages, and quick starts for each binding.

Thanks to everyone for feature requests and bug reports. I'll do my best to port this to Arm as well — but first, I'm trying to ship one more thing before year's end.

replies(2): >>46288545 #>>46288790 #
19. wat10000 ◴[] No.46288357{3}[source]
Case insensitivity is localized like anything else. I and i are equivalent, right? Not if you’re doing Turkish, then it’s I and ı, and İ and i.

In practice you can do pretty well with a universal approach, but it can’t be 100% correct.

replies(1): >>46288699 #
20. Arnt ◴[] No.46288366[source]
Ah, let's have a long discussion of this.

Unicode avoids "different" and "same", https://www.unicode.org/reports/tr15/ uses phrases like compatibility equivalence.

The whole thing is complicated, because it actually is complicated in the real world. You can spell the name of Gießen "Giessen" and most Germans consider it correct even if not ideal, but spelling Massachusetts "Maßachusetts" is plainly wrong in German text. The relationship between ß and ss isn't symmetric. Unicode captures that complexity, when you get into the fine details.

21. mxmlnkn ◴[] No.46288467[source]
I never understood why the recommended replacement for ß is ss. It is a ligature of sz (similar to & being a ligature of et) and is even pronounced ess-zet. The only logical replacement would have been sz, and it would have avoided the clash of Masse (mass) and Maße (measurements). Then again, it only affects whether the vowel before it is pronounced short or long, and there are better ways to encode that in written language in the first place.
22. fatty_patty89 ◴[] No.46288545[source]
Thank you

do the go bindings require cgo?

replies(1): >>46288586 #
23. jjmarr ◴[] No.46288569[source]
> I find it confusing when Unicode "shadows" of normal letters exist, and those are of course also dangerous in some cases when they can be mis-interpreted for the letter they look more or less exactly like

Isn't this why Unicode normalization exists? This would let you compare Unicode letters and determine if they are canonically equivalent.

replies(2): >>46289094 #>>46289684 #
24. ashvardanian ◴[] No.46288586{3}[source]
The GoLang bindings – yes, they are based on cGo. I realize it's suboptimal, but seems like the only practical option at this point.
replies(1): >>46288610 #
25. fatty_patty89 ◴[] No.46288610{4}[source]
In a normal world the Go C FFI wouldn't have insane overhead but what can we do, the language is perfect and it will stay that way until morale improves.

Thanks for the work you do

replies(1): >>46289084 #
26. ashvardanian ◴[] No.46288699{4}[source]
This is a very good example! Still, “correct” needs context. You can be 100% “correct with respect to ICU”. It’s definitely not perfect, but it’s the best standard we have. And luckily for me, it also defines the locale-independent rules. I can expand to support locale-specific adjustments in the future, but waiting for the adoption to grow before investing even more engineering effort into this feature. Maybe worth opening a GitHub issue for that :)
replies(1): >>46288797 #
27. mgaunard ◴[] No.46288760{5}[source]
Running more code per unit of data does not make the code hotter or reduce the register pressure, quite the opposite...
replies(1): >>46288861 #
28. adzm ◴[] No.46288790[source]
This is a truly amazing accomplishment. Reading these kernels is a joy!
29. mgaunard ◴[] No.46288792{5}[source]
The author published the bandwidth of its algo, it's one fifth of a typical memory bandwidth (it's not possible to go faster than memory obviously for this benchmark, since we're assuming the data is not in cache).
30. wat10000 ◴[] No.46288797{5}[source]
Right, nothing wrong with delegating the decision to a bunch of people who have thought long and hard about the best compromise, as long as it’s understood that it’s not perfect.
31. stingraycharles ◴[] No.46288861{6}[source]
You’re misunderstanding: you just convert to 32 bits once and reuse that same register all the time.

You’re running the exact same code, but are more more efficient in terms of “I immediately use the data for comparison after converting it”, which means it’s likely either in a register or L1 cache already.

32. kardianos ◴[] No.46289084{5}[source]
In a real (not "normal") world, trade-offs exist and Go choose a specific set of design points that are consequential.
33. ComputerGuru ◴[] No.46289094{3}[source]
Normalization wouldn’t address this.
replies(2): >>46289219 #>>46289262 #
34. kardianos ◴[] No.46289181[source]
Looks neat. What are all the genomic sequence comparisons in there for? Is this a grab bag of interesting string methods or is there a motivation for this?
replies(1): >>46289232 #
35. happytoexplain ◴[] No.46289219{4}[source]
What do you mean? All four normal forms of the Kelvin 'K' are the Latin 'K', as far as I can tell.
36. ashvardanian ◴[] No.46289232[source]
Levenshtein distance calculations are a pretty generic string operation, Genomics happens to be one of the domains where they are most used... and a passion of mine :)
37. nwellnhof ◴[] No.46289262{4}[source]
Normalization forms NFKC and NFKD that also handle compatibility equivalence do.
replies(1): >>46289599 #
38. mananaysiempre ◴[] No.46289599{5}[source]
A few deprecated characters, including the Kelvin and Ångström symbols, are in fact canonically equivalent to their replacements and not just compatibility equivalent, so plain NFC/NFD is enough. (It’s generally better to avoid NFKC/NFKD normalizations unless you fully understand the implications, as they do lose meaning and at the same time do not account for all possible confusables.)
39. Sesse__ ◴[] No.46289684{3}[source]
It's why the Unicode Collation Algorithm exists.

If you look in allkeys.txt (the base UCA data, used if you don't have language-specific stuff in your comparisons) for the two code points in question, you'll find:

  004B  ; [.2514.0020.0008] # LATIN CAPITAL LETTER K
  212A  ; [.2514.0020.0008] # KELVIN SIGN
The numbers in the brackets are values on level 1 (base), level 2 (typically used for accents), level 3 (typically used for case). So they are to compare identical under the UCA, in almost every case except for if you really need a tiebreaker.

Compare e.g. :

  1D424 ; [.2514.0020.0005] # MATHEMATICAL BOLD SMALL K
which would compare equal to those under a case-insensitive accent-sensitive collation, but _not_a case-sensitive one (case-sensitive collations are always accent-sensitive, too).
40. moralestapia ◴[] No.46289714[source]
Ash is amazing!

Also very cool and approachable guy.

(Best wishes if you're reading this.)

41. hans_castorp ◴[] No.46289847[source]
Would be cool if that could be integrated into Postgres :)