-
Notifications
You must be signed in to change notification settings - Fork 361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider having a configurable memory model #3673
Comments
👍 yes please! I'm very interested in this. Particularly, I would like to relax the
This is very subtle issue. I agree that in practice, most application code does not require such strong guarantees. I make this argument for Cats Effect applications. However, that application code may be calling library code that does rely on these strong guarantees. This is currently the case in Cats Effect, particularly in our runtime components. It is also very likely the case for various Thus (nearly) all applications will rely on these guarantees somewhere in the callstack. All this to say, we cannot globally disable Another complication are situations where a user wants to rely on Before we release Scala Native 0.5 and debut multi-threading, we have the opportunity to relax the memory model by default without it being a breaking change. For example, it seems attractive if we decide not to follow the JMM and disable There is of course risk in straying away from the well-established JMM :) but in general, you can make a memory model stronger backwards-compatibly, but you cannot make it weaker. Concretely, here is one proposal of how we might action this:
I need to make another review of the Java Memory Model to see if there are other areas that Scala Native may consider relaxing. But I am confident that disabling |
Thank you for lots of feedback @armanbilge and great ideas. I initially though about marking whole class with one of enum-like annotations:
However, being able to mark a single fields might be even more interesting. I like the idea of
For this one it probably would be best to use a compiler plugin settings, we already had a few in the past. This way also the solution would be more portable and would not require additional interop with each build tool During some of the recent benchmarks based on 1BRC we've found out that current memory model accommodates for almost 4x higher cpu time, and over 2x slower total time. It motivates me to change the default behaviour ASAP |
Currently following Java Memory Model imposes a significant performance regression, ~10-15%. Every
val
class member coming from scalac compiler would be treated as Javafinal
. eg.class (val x: Int){val y: AnyRef = ???}
orcase class(x: Int){val y: AnyRef}
requires us to introduceload atomic acquire
for every load, and introducefence release
after the end of constructor.Not every application would require such strong guarantees. For these we might introduce a
relaxed
memory model which would reduce amount of synchronisation, as opposed to currentstrict
memory model. The memory model should be selectable in theNativeConfig
.Alternative would to annotate specific classess or modules/packages/libraries(?, how?) to use a dedicated memory model.
The text was updated successfully, but these errors were encountered: