Live data from Hacker News

Optimising Common Lisp to try and beat Java and Rust on phone encoding 2/2

renato.athaydes.com

11–20 of 26 posts

Re: Optimising Common Lisp to try and beat Java and Rust on phone encoding 2/2

#11

The Rust code is bar far not optimized. For example while loading the dictionary, why creating a Vec and returning it instead of operating on a max word size array and reusing it. Also why not write everything at the end. I'm not a Rust Professional also, but maybe get a review by one please before benchmarking against something else.

Another point where it’s doing something that to me as a Rust expert is obviously inferior: it’s using Unicode-aware string stuff although anything non-ASCII will either be ignored (if non-alphabetic) or panic (if alphabetic). It’d certainly be better to treat the input throughout the program as a sequence of bytes rather than as UTF-8. This type of thing reminds me of the three articles ending in https://fitzgeraldn…

It's worth distinguishing between algorithmic optimizations, optimizations that generally take advantage of the language standard/runtime, and optimizations that are highly specific for one machine/platform/implementation. It's also worth keeping track of relative programmer effort to optimize.

I think most people are moderately-optimized benchmarks, i.e. moderate effort expended relative to baseline implementation effort.

That is, people are interested in getting the most performance out of the least amount of effort.

Obviously some people want and need to care about extreme peak optimization. But if you are writing benchmarks for a wide audience, that probably should not be your priority.

Re: Optimising Common Lisp to try and beat Java and Rust on phone encoding 2/2

#12
post #4

Earlier quoted context omitted.

The author was pretty explicit in the article that the rust implementation was suboptimal. I'm sure if you submitted a better implementation he'd be happy to add it in.

Eh kind of... The author was talking about a current iteration of the Rust code being suboptimal, not the current one, which the author believed was well-optimized. > The objective is to get the fastest implementation possible, and having optimised Java and Rust implementations to compare against is a motivator to keep going until there really isn’t anything else that can be tried! > Do you think Common Lisp can run…

Whoops I meant "previous iteration"

Re: Optimising Common Lisp to try and beat Java and Rust on phone encoding 2/2

#13

And here come the Rust fan boys telling us the correct way to write the code so it will be faster than anything ever written, much safer than anything ever written and better than any programming language ever written.

If there's easy out the box ways to write things that a normal Dev would do without pushing the language to its limits then it seems a bit unfair to ignore it. If I declared python to be the world's most performant concurrent language by hand wiring Cython and the deepest depths of the language and then completely ignored the out the box constructs in other languages that would be a bit misleading too.

Re: Optimising Common Lisp to try and beat Java and Rust on phone encoding 2/2

#14
post #4

Earlier quoted context omitted.

The author was pretty explicit in the article that the rust implementation was suboptimal. I'm sure if you submitted a better implementation he'd be happy to add it in.

Eh kind of... The author was talking about a current iteration of the Rust code being suboptimal, not the current one, which the author believed was well-optimized. > The objective is to get the fastest implementation possible, and having optimised Java and Rust implementations to compare against is a motivator to keep going until there really isn’t anything else that can be tried! > Do you think Common Lisp can run…

That was based on all of the rust feedback the author actually got from rust people who talked to him as opposed to people who complained in HN comments.

Hence if you want it to get even better you should provide feedback to the author, and while I absolutely respect your right to decide you can't be bothered, I don't think it's his fault that he's using code that was well-optimized according to the rustaceans who -did- talk to him.

Re: Optimising Common Lisp to try and beat Java and Rust on phone encoding 2/2

#15
post #14

Earlier quoted context omitted.

Eh kind of... The author was talking about a current iteration of the Rust code being suboptimal, not the current one, which the author believed was well-optimized. > The objective is to get the fastest implementation possible, and having optimised Java and Rust implementations to compare against is a motivator to keep going until there really isn’t anything else that can be tried! > Do you think Common Lisp can run…

That was based on all of the rust feedback the author actually got from rust people who talked to him as opposed to people who complained in HN comments. Hence if you want it to get even better you should provide feedback to the author, and while I absolutely respect your right to decide you can't be bothered, I don't think it's his fault that he's using code that was well-optimized according to the rustaceans who -d…

Oh I'm sure there's a better way to give the author feedback than sniping in HN comments.

I'm reacting to your comment here:

> The author was pretty explicit in the article that the rust implementation was suboptimal.

This is not the way the article portrays it.

Re: Optimising Common Lisp to try and beat Java and Rust on phone encoding 2/2

#16

And here come the Rust fan boys telling us the correct way to write the code so it will be faster than anything ever written, much safer than anything ever written and better than any programming language ever written.

As a Rust fanboy, Rust's advantage is that I wouldn't be afraid of dropping to its level, while I definitely wouldn't feel comfortable with C++ or C. Once the program is written, it's the usual cycle of optimizations: benchmark, flamegraph, cachegrind, etc.

Re: Optimising Common Lisp to try and beat Java and Rust on phone encoding 2/2

#17
post #14

Earlier quoted context omitted.

That was based on all of the rust feedback the author actually got from rust people who talked to him as opposed to people who complained in HN comments. Hence if you want it to get even better you should provide feedback to the author, and while I absolutely respect your right to decide you can't be bothered, I don't think it's his fault that he's using code that was well-optimized according to the rustaceans who -d…

Oh I'm sure there's a better way to give the author feedback than sniping in HN comments. I'm reacting to your comment here: > The author was pretty explicit in the article that the rust implementation was suboptimal. This is not the way the article portrays it.

Perhaps you missed the part where he said you'd need to rewrite it to use a trie to get a properly optimised one?

Re: Optimising Common Lisp to try and beat Java and Rust on phone encoding 2/2

#18
post #17

Earlier quoted context omitted.

Oh I'm sure there's a better way to give the author feedback than sniping in HN comments. I'm reacting to your comment here: > The author was pretty explicit in the article that the rust implementation was suboptimal. This is not the way the article portrays it.

Perhaps you missed the part where he said you'd need to rewrite it to use a trie to get a properly optimised one?

That's only vis-a-vis the Main.java Java implementation, which has a different algorithm, not implementation. The author is not referring to the CL implementation (note that the author explicitly calls out Main2.java, CL, and the Rust versions as being the most similar and worthy of being benchmarked). The Main.java one is more of a curio than anything else, which the author threw in because it was the first implementation they wrote (the article acknowledges it has a different algo and is therefore not directly comparable to the other two). This is not what the author is referring to when they say "well-optimised" (note that the article explicitly excludes Main.java from a lot of its valid comparisons, e.g. "Because the Rust code implements a similar algorihm to Java’s Main2, NOT Main, we should not conclude that Java can beat Rust in speed!")

The main comparison of the article is Main2.java, main.rs, and main.lisp, as the author both calls out in the article and the attached GitHub repo (as is apparent in the author's choice of optimizations; if it was a comparison of algos, then the CL and Rust versions would be rewritten to use tries as well).

The point is the author did not explicitly call out this current Rust iteration as explicitly suboptimal RE CL. The closest the article comes to calling the Rust iteration suboptimal is

> However, the Java and Rust implementations were, as CL’s, written without much thought given to performance, after all the description of the original study which introduced the problem asked participants to focus on correctness and readability, not performance.

which is referring to the previous iteration of the code, not the current one.

(It's also evident from Cryptonic and chrismorgan's comments they are talking about implementation-level concerns, not algo-level ones such as Main2.java vs the other implementations)

Re: Optimising Common Lisp to try and beat Java and Rust on phone encoding 2/2

#19
post #17

Earlier quoted context omitted.

Perhaps you missed the part where he said you'd need to rewrite it to use a trie to get a properly optimised one?

That's only vis-a-vis the Main.java Java implementation, which has a different algorithm, not implementation. The author is not referring to the CL implementation (note that the author explicitly calls out Main2.java, CL, and the Rust versions as being the most similar and worthy of being benchmarked). The Main.java one is more of a curio than anything else, which the author threw in because it was the first implemen…

Fair enough. I stand by that so far as I can tell he incorporated every implementation optimisation he got as feedback, but you're dead right that I didn't represent his wording correctly.

Re: Optimising Common Lisp to try and beat Java and Rust on phone encoding 2/2

#20
post #17

Earlier quoted context omitted.

Perhaps you missed the part where he said you'd need to rewrite it to use a trie to get a properly optimised one?

That's only vis-a-vis the Main.java Java implementation, which has a different algorithm, not implementation. The author is not referring to the CL implementation (note that the author explicitly calls out Main2.java, CL, and the Rust versions as being the most similar and worthy of being benchmarked). The Main.java one is more of a curio than anything else, which the author threw in because it was the first implemen…

There are two or three branches with different versions of the Rust code, and the author is using the fastest one. What you believe will make the Rust code faster won't, trust me.

If you think I'm wrong, could you please submit a PR and link here?

@Cryptonic 's suggestions are laughable. Try using arrays as HashMap keys in Rust :D nope, won't even compile let alone be fast. There was a way smarter attempt here to do something *based on* arrays: https://github.com/renatoathaydes/prechelt-phone-number-enco...

The DigitBytes struct is needed because just using arrays (I guess they mean slices, as arrays are obviously wrong) is incredibly slow - it would need to consider the whole array every time instead of just the relevant bytes - far slower than `Vec`. This is indeed fast, but slower than Vec.

The other suggestion: print everything at the end?? Do we even know what the objective is here? It's not to finish first, but to show to the user the results as soon as possible. It's like people don't even read the problem proposition and still think it's ok to criticize... also, Rust is using buffered IO... ALSO, the benchmark only prints a single line at the end for the two last runs, essentially doing "print it all at the end".

Post reply on HN