News for hackers. Stuff that matters.
Re:Rust 1.17 by zuzun on Thursday April 27, 2017 @04:51PM (#14214591)
Java is a bad example since it could (theoretically) do all kinds of optimizations based on runtime profiling under the hood. It also has features like deduplication, so your string might use no additional memory at all.
Re:Rust 1.17 by vog on Thursday April 27, 2017 @05:56PM (#14215098)
> Java is a bad example since it could (theoretically) do all kinds of optimizations based on runtime profiling under the hood

Isn't that true for every language?

No offense intended, but this strongly reminds me of the "Sufficiently Smart Compiler" [1]

The Java community had more than enough time to implement that, especially compared to a young language like Rust, so there's probably a reason they don't have it yet.

[1] http://wiki.c2.com/?SufficientlySmartCompiler

Re:Rust 1.17 by twic on Friday April 28, 2017 @05:19AM (#14217992)
They have implemented it.

javac compiles chained string concatenation to a sequence of StringBuilder calls, and HotSpot knows how to specifically optimize those:

https://groups.google.com/forum/m/#!topic/jvm-languages/KtVB...

That said, I'm sure there are common cases it doesn't catch.

Re:Rust 1.17 by moomin on Friday April 28, 2017 @06:31AM (#14218266)
Not really, you've identified something where the compiler spots a special case pattern and rewrites it, something available to any compiler writer who is sufficiently chummy with the standard library. I'm not saying it isn't useful, but it's nothing like the runtime optimisations the OP was talking about. It can't even handle a for loop...

Closest real world example to a sufficiently smart compiler is GHC, and that can be plenty dumb at times.

Re:Rust 1.17 by vog on Friday April 28, 2017 @09:32AM (#14219186)
Another example is the query planner of a good relational database (PostgreSQL, etc.).

Here, SQL can also be viewed as a lazy evaulated programming language, due to its declarative nature and the fact that the execution order is not defined in the code, but instead an (hopefully optimal) execution order is determined by the query planner.

Re:Rust 1.17 by twic on Friday April 28, 2017 @04:58PM (#14222996)
> Not really, you've identified something where the compiler spots a special case pattern and rewrites it

Which, string handling being specifically optimised by the compiler, is exactly what was being discussed upthread?

Re:Rust 1.17 by moomin on Friday April 28, 2017 @07:27PM (#14224009)
What was being discussed upthread went a lot further than what you're talking about. The string concat thing is a specific piece of ordinary static analysis that any language with a compile stage can perform. It's also pretty trivially defeated in ways that crop up in real code. I'm not saying it isn't useful, I'm saying it's nowhere close to what would be required to render the performance costs of doing strings the Java way equivalent to the Rust way. Therefore, to go even further upthread, Rust still provides a meaningful choice, trading Java's convenience for Rust's performance.