Scala 3 slowed us down?

262 pointsposted 2 months ago
by kmaliszewski

132 Comments

game_the0ry

2 months ago

I am not a scala fan and do not care for it, but I upvote for the thorough thought process, breakdown, and debugging of the problem. This is how technical blogs should be written. AI aint got shit on this.

sema4hacker

2 months ago

> I was refreshing one of our services. Part of this process was to migrate codebase from Scala 2.13 to Scala 3.

My first question was: why?

pxc

2 months ago

Scala 3 is sorta a new language, bringing a lot of improvements to the type system: https://docs.scala-lang.org/scala3/new-in-scala3.html

It also looks like it has some improvements for dealing with `null` from Java code. (When I last used it I rarely had to deal with null (mostly dealt with Nil, None, Nothing, and Unit) but I guess NPEs are still possible and the new system can help catch them.)

lmm

2 months ago

If you're going to "refresh" a codebase you probably want it to be on the current version of things. Old dependencies rot, like it or not. I don't think there's any timeframe for Scala 2 EOL yet, but new development is happening in 3.

dionian

2 months ago

Why not though the upgrade process from 2.13 to 3 is pretty smooth. And you get all the new language features. I can think of a few that I actually like. I’ll just mention enums because it’s a good example.

_old_dude_

2 months ago

In Scala 3, the inline keyword is part of the macro system.

When inline is used on a parameter, it instructs the compiler to inline the expression at the call site. If the expression is substantial, this creates considerable work for the JIT compiler.

Requesting inlining at the compiler level (as opposed to letting the JIT handle it) is risky unless you can guarantee that a later compiler phase will simplify the inlined code.

There's an important behavioral difference between Scala 2 and 3: in 2, @inline was merely a suggestion to the compiler, whereas in 3, the compiler unconditionally applies the inline keyword. Consequently, directly replacing @inline with inline when migrating from 2 to 3 is a mistake.

AdieuToLogic

2 months ago

> There's an important behavioral difference between Scala 2 and 3: in 2, @inline was merely a suggestion to the compiler, whereas in 3, the compiler unconditionally applies the inline keyword. Consequently, directly replacing @inline with inline when migrating from 2 to 3 is a mistake.

This reminds me of a similar lesson C/C++ compilers had to learn with the "register" keyword. Early versions treated the keyword as a mandate. As compiler optimizers became more refined, "register" was first a recommendation and then ultimately ignored.

The C++ inline keyword is treated similarly as well, with different metrics used of course.

EDIT:

Corrected reference to early C/C++ keyword from "auto" to "register".

TuxSH

2 months ago

> The C++ inline keyword is treated similarly as well, with different metrics used of course.

You are thinking of C's inline/static inline.

C++'s "inline" semantics (which are implied for constexpr functions, in-class-defined methods, and static constexpr class attributes) allow for multiple "weak" copies of a function or variable to exist with external linkage. Rather than just an optimization hint it's much more of a "I don't want to put this in any specific TU" these days.

cpeterso

2 months ago

Do you mean the ‘register’ keyword?

AdieuToLogic

2 months ago

My root-cause analysis:

I was visualizing Scala method definitions and associated the language's type inference with keyword use, thus bringing C++'s "auto" keyword to mind when the long-since deprecated "register" keyword was the correct subject.

It would appear LLM's are not the only entities which can "hallucinate" a response. :-D

AdieuToLogic

2 months ago

> Do you mean the ‘register’ keyword?

Yes I did, my bad.

kokada

2 months ago

And now we have things like `__attribute__((always_inline))` for GCC where you are completely, 100% sure that you want to inline :).

dtech

2 months ago

Kotlin heavily uses the inline keyword basically everywhere, to get rid of lamdba overhead for functions like map. Basically every stdlib and 3rd part library function that takes a lamdba is inlined.

In general it's a performance benefit and I never heard of performance problems like this. I wonder if combined with Scala's infamous macro system and libraries like quicklens it can generate huge expressions which create this problem.

pjmlp

2 months ago

This is one example why being a guest language isn't optimal.

They should have made use of JVM bytecodes that allow to optimize lambdas away and make JIT aware of them, via invokedynamic and MethodHandle optimizations.

Naturally they cannot rely on them being there, because Kotlin also needs to target ART, JS runtimes, WebAssembly and its own native version.

dtech

2 months ago

Kotlin existed before Java 7 and kept support JVM 1.6 for a long time (mainly because of Android)

Even then, they benchmarked it, and inlining was still faster* than invokedynamic and friends, so they aren't changing it now JVM 1.8+ is a requirement.

* at the expense of expanded bytecode size

gavinray

2 months ago

There are Kotlin compiler flags to default to "indy" optimization, and which may be enabled by default for some time now?

Also not all Kotlin inlines are lambdas or even include method calls

gavinray

2 months ago

The killer is specifically the inlining of macros -- which Kotlin lacks.

And not all macros, but just the ones which expand to massive expressions

Think template expressions in C++ or proc macros in Rust

dmix

2 months ago

> After upgrading the library, performance and CPU characteristics on Scala 3 became indistinguishable from Scala 2.13.

We had a similar experience moving Ruby 2->3, which has a ton of performance improvements. It was in fact faster in many ways but we had issues with RAM spiking in production where it didn't in the past. It turned out simply upgrading a couple old dependencies (gems) to latest versions fixed most of the issues as people spotted similar issues as OP.

It's never good enough just to get it running with old code/dependencies, always lots of small things that can turn into bigger issues. You'll always be upgrading the system, not just the language.

jiehong

2 months ago

> After upgrading the library, performance and CPU characteristics on Scala 3 became indistinguishable from Scala 2.13.

Checking the bug mentioned, it was fixed in 2022.

So, I’m wondering how one would upgrade to scala 3, while keeping old version of libraries?

Keeping updated libraries is a good practice (even mandatory if you get audits like PCI-DSS).

That part puzzled me more than the rest.

tasuki

2 months ago

> Keeping updated libraries is a good practice

First, the "good practice" argument is just an attempt to shut down the discussion. God wanted it so.

Second, I rather keep my dependencies outdated. New features, new bugs. Why update, unless there's a specific reason to do so? By upgrading, you're opening yourself up to:

- Accidental new bugs that didn't have the time to be spotted yet.

- Subtly different runtime characteristics (see the original post).

- Maintainer going rogue or the dependency getting hijacked and introducing security issues, unless you audit the full code whenever upgrading (which you don't).

Cpoll

2 months ago

It's true that you can satisfy the audit just by running dependency scans and updating the ones that come back vulnerable. Unfortunately, in a lot of ecosystems, that ends up looking the same as keeping all your libraries updated.

You can instead document exceptions for why all those vulnerabilities doesn't apply to your app, but that's sometimes more trouble.

mystifyingpoi

2 months ago

I'm confused as well, because he wrote

> I did it as usual - updating dependencies

but later

> After upgrading the library, performance and CPU characteristics on Scala 3 became indistinguishable from Scala 2.13.

So... he didn't upgrade everything at first? Which IMO makes sense, generally you'd want to upgrade as little as possible with small steps. He just got unlucky.

gavinray

2 months ago

It would have been a transitive dependency based on the comments about the library being "transparent" and the author unaware it was even used.

Pinning specific versions of transitive deps is fairly common in large JVM projects due to either security reasons or ABI compatibility or bugs

fn-mote

2 months ago

> Checking the bug mentioned, it was fixed in 2022.

I was considerably less impressed by the reporting when I finally found out the culprit.

Sure it was “Scala 3” … but not really.

It was an interaction of factors and I don’t think it would take away from the story to acknowledge that up front.

lmm

2 months ago

> So, I’m wondering how one would upgrade to scala 3, while keeping old version of libraries?

The normal way.

> Keeping updated libraries is a good practice

So is changing one thing at a time, especially when it's a major change like a language version upgrade.

gavinray

2 months ago

If your Maven/Gradle/SBT build specifies a version constraint for a third party lib, updating your Scala or Kotlin version doesn't affect this

(For scala-specific libs, there is a bit more nuance, because lib versions contain scala version + lib version, e.g. foolib:2.12_1.0.2 where 2.12 = scala version)

hunterpayne

2 months ago

The problem with Scala 3 is that nobody asked for it. The problem with Scala 2 is that the type inference part of the compiler is still broken. Nobody worked on that. Instead they changed the language in ways that don't address complaints. Completely ignore the market and deliver a product nobody wants. That's what happened here.

PS Perhaps they should make an actual unit test suite for their compiler. Instead they have a couple of dozen tests and have to guess if their compiler PR will break things.

thefaux

2 months ago

It's sad but I generally agree. Scala was in my view pretty well positioned for an up and coming language ~2010-15. Not only did the scala 3 rewrite fail to address many of the most common pain points -- compile times and tooling immediately come to mind -- the rewrite took many years and completely stalled the momentum of the project. I have to wonder at this point who is actually starting a new project in scala in 2025.

It's really a shame because in many ways I do think it is a better language than anything else that is widely used in industry but it seems the world has moved on.

theLiminator

2 months ago

> It's really a shame because in many ways I do think it is a better language than anything else that is widely used in industry but it seems the world has moved on.

I'm really hoping that https://flix.dev/ will learn from the mistakes of Scala. I t looks like a pretty nice spiritual successor to Scala.

still_grokking

2 months ago

> It's really a shame because in many ways I do think it is a better language than anything else that is widely used in industry but it seems the world has moved on.

No it didn't. Scala is powering some of the biggest companies on this planet.

https://business4s.org/scala-adoption-tracker/

It does apparently so well that nobody is even talking about it…

So it seems even better than all the languages people are "talking" (complaining) about.

zahlman

2 months ago

>It's sad but I generally agree. Scala was in my view pretty well positioned for an up and coming language ~2010-15

I used Scala for a bit around that period. My main recollection of it is getting Java compiler errors because Scala constructs were being implemented with deeply nested inner classes and the generated symbol names were too long.

still_grokking

2 months ago

> My main recollection of it is getting Java compiler errors because Scala constructs were being implemented with deeply nested inner classes and the generated symbol names were too long.

Sounds like you've used some beta version over 15 years ago.

Nothing like described happens in current Scala and it's like that as long as I can think back. Never even heard of such bugs like stated.

Coming up with such possibly made up stuff over 15 years later sounds like typical FUD, to be honest.

lispisok

2 months ago

I tried getting into Scala several times and kept going back to Clojure. Unless you are into type system minigames Clojure has many of the things Scala advertises but without the dumptruck of Scala overhead and complexity. Another commenter briefly touched on this but it's a language made by academics for academics to play with language design. It was a little weird it blew up in industry for a while.

acjohnson55

2 months ago

> it's a language made by academics for academics to play with language design. It was a little weird it blew up in industry for a while.

Yep. They have always been pretty honest about this.

I think that it blew up in industry because it really was ahead of its time. Type systems were pretty uncool before Scala. It proved that you could get OO and FP in a single type system.

Actually, a big part of reason for doing Scala 3 was rebasing the language on a more rigorous basis for unifying OO and FP. They felt that for all their other big ideas, it was time to rethink the fundamentals.

refulgentis

2 months ago

> Type systems were pretty uncool before Scala

I’m not up on programming language engineering as much as I should be at 37, could you elaborate a bit here? (To my untrained ear, it sounds like you’re saying Scala was one of the first languages that helped types break through? And I’m thinking that means, like, have int x = 42; or Foo y = new Foo()”

still_grokking

2 months ago

> It was a little weird it blew up in industry for a while.

It never went away. It only got more:

https://business4s.org/scala-adoption-tracker/

Rogach

2 months ago

Wow, 34 companies with "possibly" 233 more!

I don't see the chart with changes of number of companies using Scala over time. But even without the chart - if after 15 years there are less than 300 companies in total, that's a bit depressing.

Of course legacy never goes away, and even 20 years down the line there will still be some demand for Scala programmers. Similar to how Cobol still lives on. But in my experience the language isn't growing anymore, even slowly dwindling in userbase. And this became way worse after Scala 3 mess.

dionian

2 months ago

The simplicity of closure is certainly a main part of its appeal. I’ve never done OOP in it, but I don’t think I want to. I have a lot of respect for it though.

monksy

2 months ago

It was absolutely amazing how stubborn and ridiculous the whole bracket-less syntax change was handled. It was basically a dictatorial decision that they pretended to be a community decision. It was just pushed and tons of people voiced their disapproval. In the end it was "so bad so sad you can always reenable brackets".

They did it to try to appeal to Pythonists.. turns out that wasn't why Pythonists didn't use scala in the first place.

dionian

2 months ago

I think it’s nice to be able to use it. But like pretty much everything in scala, it’s a huge smorgasbord of things from which you can choose. I personally don’t use that syntax, but it’s cool that I can and sometimes I do just for fun.

jll29

2 months ago

A language should not be complicated. (Wish Odersky, capable as he is, kept working on his much-verlooked TurboModula).

Simple:

- Scheme

- C

- Pascal

- Go

- Lua

Complicated

- PL/1

- C++ 2024

- Scala 3

Still borderline or beyond?

- Rust

- Java (>850 pp. lang. specification...)

still_grokking

2 months ago

> In the end it was "so bad so sad you can always reenable brackets".

This is not true.

Nobody ever proposed to replace the old syntax!

The new syntax was, and is, optional, and that's exactly like designed from the very beginning.

Rogach

2 months ago

They didn't explicitly propose replacing the syntax, true. But to an outsider, it sure looked like the new syntax was a priority - all the examples and code snippets in the official docs defaulted to the new syntax, making them infuriating to read for someone accustomed to braces.

If I recall correctly, later they added a switch allowing one to choose between syntax versions in the online docs. But it wasn't done right from the start, and when that was finally added most of the damage was done, people already lost interest.

I understand that removing braces might feel harmless - but it really makes the code harder to read for people that use braces all the time.

If someone's brain is accustomed to seeing braces everywhere, reading code with them becomes almost automatic, handled by "low-level" parts of the brain. If the syntax is changed, then "low-level" brain areas have to pass work to "higher-level" areas, which increases energy requirements and processing latency. So reading unfamiliar syntax is literally harder.

Incidentally, that's also why many people are so picky about grammar - grammatical errors make the text noticeably harder to read.

Source: have a degree in neurophysiology.

ergocoder

2 months ago

You capture the root issue quite well.

Now every tool has to adapt to Scala 3. And you guess it? It will take time. Even IntelliJ still doesn't correctly highlight syntax on some parts that also exist in Scala 2. And this has been years after Scala 3 was launched. It's mind-boggling.

They could have improved upon Scala 2 and incrementally add more capabilities. It's obvious they don't care about Scala's industry success. They care mostly about the academic success. Nothing wrong with that, but that should be made very clear.

In Scala, they have a huge debate with zealots arguing against, for example, early return; they would describe how bad it will be blah blah blah e.g. https://tpolecat.github.io/2014/05/09/return.html, meanwhile Kotlin supports early return with absolutely no issue.

oelang

2 months ago

And I wish you read the article, you're comments are completely off topic.

voidfunc

2 months ago

Scala has deep roots in the Ivory Towers of Academia, its not shocking they think they know better than their users what the problems with the language are and didn't do any kind of real product management to figure out the actual problems before embarking on a rebuild.

js8

2 months ago

It wouldn't be a problem, but the issue is a one of expectations.

Was Scala supposed to be a research language (focus on novel features) or an industrial language (focus on stability and maintainability)? I think Oderski wanted the first but many people wished for the second.

lmm

2 months ago

> The problem with Scala 2 is that the type inference part of the compiler is still broken. Nobody worked on that. Instead they changed the language in ways that don't address complaints.

Huh? Type inference is much more consistent and well-specified in 3. In 2 it was ad-hoc so and impossible to fix anything for one codebase without breaking another. There are plenty of legitimate complaints to be had about Scala 3, but this is absolutely not one of them.

vletal

2 months ago

I was so stoked, when it was released. Loved the approach they take. So, I can say, there was at least one person who asked for it.

With the hindsight, it is not a great mainstream language and the new opinionated language is too hard for junior Joe developers.

Anyway, you clearly have not read the article, as it is about bug in a transitive dependency, not an actual Scala 3 issue.

p.s.: Scala compiler is one of the most aggressively tested pieces of software in the JVM ecosystem.

still_grokking

2 months ago

> PS Perhaps they should make an actual unit test suite for their compiler. Instead they have a couple of dozen tests and have to guess if their compiler PR will break things.

You did not even try to formulate it in a way that could be interpreted as you just not knowing; instead you make blatant false statements in the most confident way possible.

Your statement is therefore an outright lie, spreading FUD.

As a matter of fact the Scala compiler has thousands, likely even tens of thousands of test cases.

https://github.com/scala/scala3/tree/main/tests

But that's not all. Scala (2 & 3) has also a test case called "community build" where new compiler releases are tested by compiling millions of LOCs from all kinds of Scala OpenSource projects.

https://github.com/VirtusLab/community-build3

https://github.com/scala/community-build

derriz

2 months ago

I was involved in a Scala point version migration (2.x) migration a few years ago. I remember it being painful. Although I recall most of the pain was around having lots of dependencies and waiting for libraries to become available.

At the time Scala was on upswing because it had Spark as its killer app. It would have been a good time for the Scala maintainers to switch modes - from using Scala as a testbed for interesting programming-language theories and extensions to providing a usable platform as a general commercially usable programming language.

It missed the boat I feel. The window has passed (Spark moved to Python and Kotlin took over as the "modern" JVM language) and Scala is back to being an academic curiosity. But maybe the language curators never saw expanding mainstream usage as a goal.

hylaride

2 months ago

Outside of Android work, has Kotlin really taken over? My understanding is that Java added a lot of functional programming and that took a lot of wind out of Scala's sails (though Scala's poor tooling certainly never helped anything).

mystifyingpoi

2 months ago

> My understanding is that Java added a lot of functional programming

This is true, but needs more context. Java 8 added Stream API, which (at this time) was a fantastic breath of fresh air. However, the whole thing felt overengineered at many points, aka - it made complex things possible (collector chaining is admittedly cool, parallel streams are useful for quick-and-dirty data processing), but simple everyday things cumbersome. I cannot emphasize how tiring it was to have to write this useless bolierplate

  customers.stream().map(c -> c.getName()).collect(Collectors.joining(", "))
for 1000th time, knowing that

  customers.map(c -> c.getName()).join(", ")
is what users need 99.99999% of the time.

still_grokking

2 months ago

It's such a blessing to be able to write in Scala

  customers.map(_.name).mkString(", ")
instead of the Java bloat

  customers.stream().map(c -> c.getName()).collect(Collectors.joining(", "))

bvrmn

2 months ago

It bothers me that majority of languages ignores a nice python approach. `', '.join(any_str_iterable)`. Instead of supporting join for myriads of containers there is a single str method.

dtech

2 months ago

Sort of true, but I often hear this take from Java programmers and it feels like "Blub" [1]/Stockholm syndrome to me.

Personally, I'm extremely glad to not have had to write .toStream().map(...).collect(Collectors.list()) or whatever in years for what could be a map. Similar with async code and exception handling.

For me one of the main advantages of Kotlin is that is decreases verbosity so much that the interesting business logic is actually much easier to follow. Even if you disregard all the things it has Java doesn't the syntax is just so much better.

[1] https://paulgraham.com/avg.html

aarroyoc

2 months ago

At least where I work, writing new Java code is discouraged and you should instead use Kotlin for backend services. Spring Boot which is the framework we use, supports Kotlin just fine, at the same level as Java. And if you use Jetbrains tools, Kotlin tooling is also pretty good (outside Jetbrains I will admit it is worse than Java). Now, even in new Java projects you can still be using Kotlin because it is the default language for Gradle (previously it was Groovy).

gavinray

2 months ago

My org had to write a pivotal backend service on the JVM, due to JDBC having the largest number of data source adapters.

The choice was Kotlin. Scala is too "powerful" and can be written in a style that is difficult for others, and Java too verbose.

Kotlin is instantly familiar to modern TypeScript/Swift/Rust etc devs.

The only negative in my mind has been IntelliJ being the only decent IDE, but even this has changed recently with Jetbrains releasing `kotlin-lsp` for VS Code

https://github.com/Kotlin/kotlin-lsp

kelnos

2 months ago

Java did indeed add more FP to the language, but Java's type system is still fairly primitive compared to Scala's.

esafak

2 months ago

Java's new features are always going to be on paper. The ecosystem, with all its legacy code, is always going to be a decade behind. And if you are starting a new project, why would you pick Java over Kotlin?

frje1400

2 months ago

> And if you are starting a new project, why would you pick Java over Kotlin?

Because in 5-10 years you'll have a Java project that people can still maintain as if it's any other Java project. If you pick Kotlin, that might at that point no longer be a popular language in whatever niche you are in. What used to be the cool Kotlin project is now seen as a burden. See: Groovy, Clojure, Scala. Of course, I recognize that not all projects work on these kinds of timelines, but many do, including most things that I work on.

pjmlp

2 months ago

Because the Java Virtual Machine is designed for Java, and that is what all vendors care about.

Kotlin is Google's C#, with Android being Google's .NET, after Google being sued by coming up with Google's J++, Android Java dialect.

Since Google wasn't able to come up with a replacement themselves, Fuchsia/Dart lost the internal politics, they adopted the language of the JetBrains, thanks to internal JetBrains advocates.

vips7L

2 months ago

The ecosystem is perfectly fine. You’re more than likely using the ecosystem when you choose Kotlin, that’s the whole point. This comment doesn’t make any sense.

spicybbq

2 months ago

> And if you are starting a new project, why would you pick Java over Kotlin?

I've written multiple production services in Kotlin Spring Boot. Now, we're building a new system and using Java 21 (25 soon).

Why? Kotlin the language is great, but there are corresponding tradeoffs in interop. Meanwhile, Java the language has improved to the point that it's good enough, and Java feels like it's headed in the right direction. In my opinion, AI models are better at Java than Kotlin. If you prefer a weaker claim, the models are trained on more Java code than Kotlin code.

Finally, from an enterprise perspective, it is a safer long-term investment for a Java shop to own an application written in Java rather than in Kotlin.

hylaride

2 months ago

That's kind of what I'm asking. I did have a former co-worker write a micro service in Kotlin around 2018. He said that as nice as the language is, the ecosystem was (at the time, not sure how it is today) so utterly dominated by Android development, that he said he wouldn't recommend using it again - half the time he was calling out Java anyways.

adrianN

2 months ago

It’s a lot cheaper to hire for Java than for „modern“ languages.

wrathofmonads

2 months ago

Kotlin hasn’t made much of an impact in server-side development on the JVM. I’m not sure where this perception comes from, but in my experience, it’s virtually nonexistent in the local job market.

strobe

2 months ago

another issue with kotlin, because it encourage Java ecosystem usage like Spring is not much differentiation that could drive adoption.

izacus

2 months ago

Why is your personal experience relevant to the wider market? How many companies and locations did you survey for that?

pjmlp

2 months ago

Kotlin is an Android language, because Google says so, and they stiffle Java support on purpose (Java 17 LTS subset currently).

Outside Android, I don't even care it exists.

If I remember correctly, latest InfoQ survey had it about 10% market share of JVM projects.

xolve

2 months ago

The bug reports linked on softwaremill and scala GitHub's are precise and surprisingly small fixes! It does show Scala's power in expressiveness.

Scala is a great language and I really prefer its typesafe and easy way to write powerful programs: https://www.lihaoyi.com/post/comlihaoyiScalaExecutablePseudo... Its a great Python replacement, especially if your project is not tied to ML libraries where Python is defacto, like JS on web.

spockz

2 months ago

For me the main takeaway of this is that you want to have automated performance tests in place combined with insights into flamegraphs by default. And especially for these kind of major language upgrade changes.

malkia

2 months ago

Benchmarking requires a bit of different setup than the rest of the testing, especially if you want down to the ms timings.

We have continous benchmarking of one of our tools, it's written in C++, and to get "same" results everytime we launch it on the same machine. This is far from ideal, but otherwise there be either noisy neighbours, pesky host (if it's vm), etc. etc.

One idea that we thought was what if we can run the same test on the same machine several times, and check older/newer code (or ideally through switches), and this could work for some codepaths, but not for really continous checkins.

Just wondering what folks do. I can assume what, but there is always something hidden, not well known.

spockz

2 months ago

I agree for measuring latency differences you want similar setups. However, by running two versions of the app concurrently on the same machine they both get impacted more or less the same by noisy neighbours. Moreover, by inspecting the flamegraph you can, manually, see these large shifts of time allocation quickly. For automatic comparison you can of course use the raw data.

In addition you can look at total cpu seconds used, memory allocation on kernel level, and specifically for the jvm at the GC metrics and allocation rate. If these numbers change significantly then you know you need to have a look.

We do run this benchmark comparison in most nightly builds and find regressions this way.

malkia

2 months ago

Good points there - Thanks @spockz!

esafak

2 months ago

https://en.wikipedia.org/wiki/Hardware_performance_counter can help with noisy neighbors. I am still getting into this.

spockz

2 months ago

Yes, that can help with detecting how much cpu was actually used during the run. But it doesn’t influence benchmark results. Not sure how exactly to use it for doing subsequent runs and comparing final performance. Then this needs to be extrapolated to final performance in production.

esafak

2 months ago

What are folks using for perf testing on JVM these days?

cogman10

2 months ago

For production systems I use flight recordings (jfrs). To analyze I use java mission control.

For OOME problems I use a heap dump and eclipse memory analysis tool.

For microbenchmarks, I use JMH. But I tend to try and avoid doing those.

spockz

2 months ago

I use jmh for micro benchmarks on any code we know is sensitive and to highlight performance differences between different implementations. (Usually keep them around but not run on CI as an archive of what we tried.)

Then we do benchmarking of the whole Java app in the container running async-profiler into pyroscope. We created a test harness for this that spins up and mocks any dependencies based on api subscription data and contracts and simulates performance.

This whole mechanism is generalised and only requires teams that create individual apps to work with contract driven testing for the test harness to function. During and after a benchmark we also verify whether other non functionals still work as required, i.e. whether tracing is still linked to the right requests etc. This works for almost any language that we use.

user

2 months ago

[deleted]

noelwelsh

2 months ago

jmh is what I've always used for small benchmarks.

pjmlp

2 months ago

The only issue I have with Scala 3 is Python envy, they should not have come up with a second syntax, and pushing it as the future.

If anything is slowly down Scala 3 is that, including the tooling ecosystem that needs to be updated to deal with it.

gedy

2 months ago

As a former Scala fan, wow you aren't kidding, wth

    val month = i match
        case 1  => "January"
        case 2  => "February"
        // more months here ...
        case 11 => "November"
        case 12 => "December"
        case _  => "Invalid month"  // the default, catch-all
    
    // used for a side effect:
    i match
        case 1 | 3 | 5 | 7 | 9  => println("odd")
        case 2 | 4 | 6 | 8 | 10 => println("even")
    
    // a function written with 'match':
    def isTrueInPerl(a: Matchable): Boolean = a match
        case false | 0 | "" => false
        case _ => true

jfim

2 months ago

It's been a while since I touched Scala but wasn't that a thing in previous versions, minus the braces not being present?

weego

2 months ago

Yes, that's all just as it was, and in places braces were not required / interchangeable so this is more of an optional compiler choice than a real change

malkia

2 months ago

Sorry, I'm coming from C++-ish background - can anyone explain what's going on :)

hocuspocus

2 months ago

Scala 2's syntax is mostly Java/C-style with a few peculiarities.

Scala 3's optionally allows indentation based, brace-less syntax. Much closer to the ML family or Python, depending on how you look at it. It does indeed look better, but brings its share of issues.[1] Worse, a lot of people in the community, whether they like it or not, think this was an unnecessary distraction on top of the challenges for the entire ecosystem (libraries, tooling, ...) after Scala 3.0 was released.

- [1] https://alexn.org/blog/2025/10/26/scala-3-no-indent/

bdangubic

2 months ago

madness :)

a24j

2 months ago

Can you eli5 the madness? And how that relates to python/java?

noelwelsh

2 months ago

Everything is up to date with the new syntax as far as I'm aware. Also, the compiler and scalafmt can rewrite one to the other. A project can pick whatever style it wants and have CI reformat code to that style.

lmm

2 months ago

> Everything is up to date with the new syntax as far as I'm aware.

The Eclipse plugin isn't, and none of the newer IDE integrations is reliable.

pjmlp

2 months ago

When I checked a year ago, the IDE tooling still wasn't quite there.

spockz

2 months ago

What I don’t get because there is LSP and BSP support. What else is needed to get support for scala 3 from an IDE? Obviously, Kotlin coming from Jetbrains will make it receive a lot more love and first class support.

blandflakes

2 months ago

I always find downvoting on stuff like this perplexing. It still isn't there. I know that a lot of Scala people are doing metals and some kind of text editor experience, but if you've used something as powerful as Intellij, the Scala 3 experience is a serious downgrade, and it still is today, even though it's better than it was a year ago.

ergocoder

2 months ago

It's on brand for Scala to have multiple ways of achieving the same thing.

Now we x2 by having the curly brace syntax and the indent syntax.

esafak

2 months ago

You could also have compared it, more attractively, to Haskell.

pjmlp

2 months ago

Except the reason behind the syntax change is the losing mindshare from Scala into Python, after its relevance in the big data wave that predated the current AI wave.

Nothing to do with Haskell, even if it is also white space significant.

scotty79

2 months ago

It's quite impressive that you can swap out major version from under running application and have just one subtle issue.

still_grokking

2 months ago

The upgrade Scala 2 -> 3 is usually super smooth. The compiler does all the work, you just need to update your build config / dependencies.

The only exception is macros: If you used the experimental Scala 2 macros you need to migrate them to the new system which is completely different.

esarbe

2 months ago

Awesome language, nice to see others using it.

I can thoroughly recommend it. Once of the best languages out there in terms of expressive power.

Kwpolska

2 months ago

The takeaway of upgrading your libraries when upgrading major language and framework versions applies beyond Scala. Especially when the libraries abuse magic language features (and far too many Scala libraries do) or otherwise integrate deep into the framework/language.

still_grokking

2 months ago

> Especially when the libraries abuse magic language features (and far too many Scala libraries do)

Would you mind to explain what you mean?

groundzeros2015

2 months ago

I know this topic has been beat to death but this is another example of why high level language with super optimizing compiler has had less industry success.

If performance is a feature it needs to be written in the code. Otherwise it implicitly regresses when you reorder a symbol and you have no recourse to fix it, other than fiddling to see if it likes another pattern.

alberth

2 months ago

To be fair, it’s misleading to group Scala (or any JVM language), with other “high-level languages.”

The JVM is extremely mature and performant, and JVM-based languages often run 5x (or more) than non-JVM high-level languages like Python or Ruby.

groundzeros2015

2 months ago

That doesn’t follow. Scala is a high level language and compiler above the JVM. The bug here is a high level one:

> Turns out there was indeed a subtle bug making chained evaluations inefficient in Scala 3

I’m comparing with Haskell, Scheme, or even SQl which all promise to compile efficient code from high level descriptions.

blandflakes

2 months ago

The bug in TFA is hardly a reason that Scala is not a success, though.

rr808

2 months ago

I'm on Spark Scala 2 project and I hate it. Basically any good Scala dev would never want to work on our ETL projects, so we get second rate Python or Java devs like me who bastardize the language to get anything to work. Most of our new stuff is all pyspark, hopefully we can replace Scala asap.

still_grokking

2 months ago

What's so bad about it?

Why not try to learn it for good?

user

2 months ago

[deleted]

phendrenad2

2 months ago

Controversial opinion: Scala should have gone into maintenance mode a decade ago. They got the language right at the beginning, and a decade of tinkering has just fatigued everyone and destroyed any momentum the language once had.

instig007

2 months ago

> and a decade of tinkering has just fatigued everyone and destroyed any momentum the language once had.

it's hard to buy it, considering that many of those "fatigued" moved on Kotlin, led by their managers' bs talking points.

hunterpayne

2 months ago

Many of the Scala projects got people fired. Something the Scala devs largely ignore. Plus Scala support is truly awful even by the low standards of an OpenSource project. Then there is the fact that the Scala specific libraries are largely dead.

Scala had/has a lot of promise. But how the language is marketed/managed/maintained really let a lot of people down and caused a lot of saltiness about it. And that is before we talk about the church of type-safety.

Scala is a more powerful language than Kotlin. But which do you want? A language with decent support that all your devs can use, or a language with more power but terrible support and only your very best devs can really take advantage of. And I say this as someone writing a compiler in Scala right now. Scala has its uses. But trying to get physicists used to Python to use it isn't one of them. Although that probably says more about the data science folks than Scala.

PS The GP is right, they should have focused on support and fixing the problems with the Scala compiler instead of changing the language. The original language spec is the best thing the Scala devs ever made.

hocuspocus

2 months ago

Kotlin has become a pretty big and complex language on its own so I'm not sure this is a good counterexample.

The fundamental issue is that fixing Scala 2 warts warranted an entirely new compiler, TASTy, revamped macros... There was no way around most of the migration pains that we've witnessed. And at least the standard library got frozen for 6+ years.

However I agree that the syntax is a textbook case of trying to fix what ain't broke. Scala 3's syntax improvements should have stuck to the new given/using keywords, quiet if/then/else, and no more overloaded underscore abuse.

still_grokking

2 months ago

> The original language spec is the best thing the Scala devs ever made.

The overreaching majority thinks that Scala 3 is objectively much better than Scala 2 ever was. That's at least what you hear just everywhere, besides the occasional outlier by some Scala 2 die hards.

lmm

2 months ago

> Scala had/has a lot of promise. But how the language is marketed/managed/maintained really let a lot of people down and caused a lot of saltiness about it. And that is before we talk about the church of type-safety.

On the contrary, there was nothing wrong with Scala's marketing. What's damaged it is a decade of FUD and outright lies from the people marketing Kotlin.

still_grokking

2 months ago

Sure. All successful languages go into decades still stand.

Just see how great this worked out for Java (or Perl… ;-))!

/s

atbpaca

2 months ago

Thank you for sharing. Interesting insight on dep libraries.

munchler

2 months ago

I’m not familiar with Scala’s macro system, but it seems like a big takeaway here is: Be careful with code that invokes the compiler (JIT) at runtime. That seems like it’s asking for trouble.

dtech

2 months ago

Macro's are compile time, there is no runtime codegen.

The problem was overly-frequent inlining generating enormous expressions, causing a lot JIT phase and slow execution.

munchler

2 months ago

Thank you for the clarification. If I understand correctly, these large expressions are created at compile-time, but the impact isn't felt until JIT occurs in the runtime environment. In that scenario, shouldn't the JIT just run once at startup, though? I'm still not quite understanding how JIT can take so much time in a production environment.

hunterpayne

2 months ago

Because the jit will let the unoptimized code run a few (hundred) times to take measurements to know what needs to be optimized and how it needs to be optimized. This is a good solution and makes hotspot very effective. The problem is that it happens randomly a few minutes/seconds into the operation of the service. So you randomly have a big pause with the performance hit everytime you run the service. The upside is that this only happens once. But you have to plan for a big performance hit to requests which are unlucky enough to be called at the wrong time.

gavinray

2 months ago

That's not true, Spark's entire query engine relies on use of runtime codegen via macros/quasi quotes

Look up the architecture of Catalyst + Tungsten

https://www.databricks.com/glossary/catalyst-optimizer

lmm

2 months ago

Catalyst uses runtime codegen, sure, but the OP wasn't using that.