Skip to content

v2: 5x swifter CPython bindings and first NodeJS bindings

Choose a tag to compare

@ashvardanian ashvardanian released this 10 Oct 04:36
· 2585 commits to main since this release

Python

So why would anyone replace the easy-to-use PyBind11 with almost 2,000 lines of pure CPython bindings?! Of course, to lower the latency! PyBind11 wraps every C++ object with a smart pointer, puts a hash table next to it, and addresses function pointers with std::string key lookups 馃く

Let's see where it gets us if benchmarking with the "Leipzig1M" dataset. The bandwidth-oriented functions are just as fast as in the past:

  • Hashing the dataset: 77 ms for 馃悕 vs 16 ms for 馃 ~ 4.5x faster
  • Counting the number of "the": 151 ms for 馃悕 vs 45 ms for 馃 ~ 3.3x faster
  • Split all whitespace-delimited words: 782 ms for 馃悕 vs 338 ms for 馃~ 2.3x faster
  • Split around every "the": 240 ms for 馃悕 vs 48 ms for 馃 ~ 5x faster

What about the latency-oriented ones?

  • Find the first whitespace: 1 碌s for 馃悕 vs 3 碌s for 馃 ~ 3x slower, where previously it was 15碌 and 15x slower
  • Partition around the first whitespace: 73 ms for 馃悕 vs 33 碌s for 馃 ~ 2212x faster 馃コ

JavaScript

In an effort to bring faster string operations, together with @nairihar, we have started the NodeJS binding. It's just a skeleton, and has poor performance for now, but you can use it as a starting point to help us implement faster Str class for JavaScript 馃