News for hackers. Stuff that matters.
Re:Why Is C Faster Than Java (2009) by JetSetWilly on Monday December 27, 2021 @04:59AM (#29701108)
That's just because there's no a lucene equivalent C library with the same level of attention?

however, there are increasingly such written in C++ (pisa) and rust (tantivy). They handily beat lucene in benchmark suites [1] - so it seems like lucene does suffer from a java penalty - despite getting even more developer attention than pisa and tantivy I would think.

1: https://tantivy-search.github.io/bench/

Re:Why Is C Faster Than Java (2009) by jillesvangurp on Monday December 27, 2021 @05:35AM (#29701282)
No, because a lot of the work would end up being the same kind of work with no inherent advantages of one over the other. Easy to predict because there used to be a C implementation of Lucene. It couldn't keep up in terms of features or performance so work on that stopped a long time ago.

Most of the libraries you mention don't come close to even implementing a tiny portion of Lucene. Classic case of apples and oranges. Also, good examples of the niche things I was talking about. Benchmarks like you mention are kind of self serving like that. They measure something but not everything and probably very selectively. They are faster at what exactly? Under what circumstances? Why? As soon as you answer those questions, what inherent limitations do the Lucene developers have replicating that?

A lot here boils down to how the underlying search engine implements tokenization, stemming, language analyzers, fuzzy matching, and a few other things that you'd need to build a search engine that doesn't suck. The benchmark conveniently does not specify any of that; presumably because it lacks many of those features or has extremely naive implementations of those things. That would be the kind of corner cutting I was talking about. What kind of relevance ranking is being used here? How good is it? Was that even evaluated or considered? Hint, Lucene gives you many options here. Search quality and performance are the big trade off here. Anything that trades off quality over performance is going to look good until you look at the quality.

Also things like the index size and document volume are not specified. Or the hardware this ran on. Or the JVM configuration, compiler flags, etc. It's like benchmarking a formula 1 car by how quick it is at parallel parking. Yes, a T-Ford is going to be faster at that maybe. But is that even meaningful to look at?

Re:Why Is C Faster Than Java (2009) by JetSetWilly on Monday December 27, 2021 @05:52AM (#29701353)
Sure - there's no doubt that lucene is a much bigger and more "enterprise" solution that is used professionally today by many big companies from Elasticsearch to Mongo to Solr.

But for core text search and indexing - tantivy does indeed support tokenization, stemming, fuzzy matching, and so on. For the core use case of performing a text search on a large corpus of text a lot of the functionality one would need is there - as you can see if you look at the list of queries in the benchmark. From the list of queries there's little I would miss from our "enterprise" use of lucene today - speaking for myself.

One might argue "oh but if you add some obscure features that 5% of people use like a real enterprise solution then it will slow down by 2x" - but I doubt it.

To me, tantivy and the likes are a technology demonstrator - they show that lucene could be significantly faster if it wasn't in java.

Re:Why Is C Faster Than Java (2009) by jillesvangurp on Monday December 27, 2021 @06:17AM (#29701496)
The whole point of a search engine is getting you good results. Not alright result, or some random results in the wrong order, but the best possible results. Bench marking relevance is much more important than bench marking performance for search.

Lucene is a Swiss army knife for building you something to get you the best results possible. Those aren't enterprise features if you actually care about what your users do with search results. For example because your sales are directly correlated to that. The trick with Lucene is to do as much as you can possibly get away with as opposed to doing as little as you can do to call it a day that seems to be the strategy here for proving X is faster than Y with this particular benchmark. It's faster because it does less useful work.

The proof of concept here would be building something that is as good and as fast. By not even trying to benchmark how good things are, you kind of make the point that you either don't know or don't care enough to even bother to measure it.

Re:Why Is C Faster Than Java (2009) by JetSetWilly on Monday December 27, 2021 @06:24AM (#29701538)
Why did you offer lucene as a counterpoint, if you deny that there’s any equivalent implementation elsewhere that isn’t lucene? That just means lucene cannot be a counterpoint if it just so happens that the only implementation is in java.
Re:Why Is C Faster Than Java (2009) by jillesvangurp on Monday December 27, 2021 @06:43AM (#29701666)
Because people have been trying pretty hard to replicate what Lucene does in other languages specifically because they thought they could do a better job. The reason the Java implementation continues to dominate is that it being implemented in Java has repeatedly proven to be not as much of an issue as people assume it to be. At least not enough to matter.

And since the article is called "why C is faster than Java" and the main argument is literally "here's this thing implemented in C that is fast", it's an excellent counterpoint to go "here's this other thing in Java that is fast".

Re:Why Is C Faster Than Java (2009) by JetSetWilly on Monday December 27, 2021 @07:00AM (#29701761)
Sure, I would agree that lucene is “fast enough”. But that doesn’t mean it couldn’t be faster if implemented in another language, and I believe that tantivy demonstrates that it could be.

A historical accident isn’t a counterpoint.

Re:Why Is C Faster Than Java (2009) by zelphirkalt on Monday December 27, 2021 @06:23AM (#29701533)
This however, throws out all productivity, that a language like Java gives developers in contrast to C, plus memory management. The C equivalent most likely would be a buggy version with the typical memory management issues, or consume much more time to create.

I am not a big Java fan. We are not talking a Haskell or Rust or similarly safe language here. However, Java is still far ahead of C in that regard.

Re:Why Is C Faster Than Java (2009) by JetSetWilly on Monday December 27, 2021 @06:36AM (#29701621)
From what I’ve seen working in the financial industry, hardly anybody uses lucene directly. It is typically behind elasticsearch or solr or whatever - which then takes care of load balancing and replication and all that.

For these use cases, you could swap out lucene for something faster or more “low level” in implementation without affecting the typical application using it much, as all interaction happens across some rest API.

Re:Why Is C Faster Than Java (2009) by zelphirkalt on Monday December 27, 2021 @07:18AM (#29701877)
The point I am making is, that you would have to write that lower level or somehow different thing first. If you do it in C, then how do you make it as safe, while still having the same functionality? In huge projects this has mostly not been achieved. Large C projects (and C++ project) suffer from memory safety issues. This seems to be the general rule. Even the best make mistakes, when working with big C code bases, or there are so few of those "best", that they cannot possibly create a huge project all by themselves.

If you replace a more or less safe implementation, with a buggy, memory unsafe C version of it, you are not going to make anyone happy about the performance improvement. Always assuming, that you put in "only" the same amount of time and number of people, not more, than the original implementation.

The amount of things you need to keep in mind with all the memory management and other details when writing C code can also make you blind to other issues like proper input validation and implementation of invariants of application settings. You have to put a lot of energy into making sure you are not leaking memory and avoiding memory safety issues, so you lack that energy when it comes to higher level issues. This is directly affecting developer productivity.

Re:Why Is C Faster Than Java (2009) by JetSetWilly on Monday December 27, 2021 @07:39AM (#29702011)
I mean, obviously using different languages has different trade offs in many dimensions. If speed were all that mattered then everything would be written in assembler.

But the point at issue is that by using java you are trading off speed (potentially for other benefits).

By the way - tantivy at least is implemented in rust so it shouldn’t suffer from memory safety issues just as lucene shouldn’t. And the rust language will provide some guarantees that java doesn’t - like freedom from data races.

Re:Why Is C Faster Than Java (2009) by Too on Monday December 27, 2021 @10:41AM (#29703349)
The premise here was writing the lower piece something. Not using it.
Re:Why Is C Faster Than Java (2009) by dig1 on Monday December 27, 2021 @05:57AM (#29701376)
> there's no a lucene equivalent C library with the same level of attention?

Actually, there is [1]. Clucene has been around for years, it is a re-implementation of Lucene in C++, and yet the only serious usage I've seen was it as a file indexing engine in KDE many years ago (although I might miss other projects). Later it was dropped from KDE.

I've had (indirect) relations with search/indexing stuff for years, and no one ever complained about Lucene's speed or had any problems with it.

[1] http://clucene.sourceforge.net/

Re:Why Is C Faster Than Java (2009) by spaetzleesser on Monday December 27, 2021 @12:00PM (#29704190)
There used to be a C Lucene version. I used it for a desktop software. It was way faster than the Java version but wasn't maintained well.
Re:Why Is C Faster Than Java (2009) by chx on Monday December 27, 2021 @09:16AM (#29702654)
For C++ wouldn't Manticore, the Sphinx Search fork be a better example?