-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Override getOrElse in Map1, Map2, Map3 and Map4 to avoid allocations. #6138
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
Conversation
@adriaanm Hello. I'm not sure if you are the person to address to but readme says that you are associated with 'infrastructure' so here's the issue: |
If you open the full build log (accessible by clicking "Details" on
This test is testing that the small I'm pretty sure that you can fix this by putting |
@hrhino Wow! Thank you very much for such detailed explanation. Will try that attribute. Though I'm somewhat scared with unforeseeable (for me) consequence of a very small changes like that and it's awesome that there were tests for that. My guess is that I should add serialization tests for MapN and fix their SVUID as well. |
@hrhino I added tests (green on unmodified codebase) and then applied my changes along with |
That's the MiMa check failing. In general, Scala provides a strong binary compatibility guarantee for the standard library. This means that any code compiled against version 2.12.x of the library can be run with version 2.12.y of the library on the classpath, and still work. Adding or removing public fields or methods breaks that guarantee, since a user could call/access that field/method and potentially receive a runtime error. In this case, the problem is that long foo = scala.collection.immutable.Map.Map1.serialVersionUID; which would compile against 2.12.5 but break if run with 2.12.4 on the classpath (as that field is not there). If you think that's a bit silly in this case, you're not alone: ProblemFilters.exclude[MissingFieldProblem]("scala.collection.immutable.Map#Map1.serialVersionUID")
ProblemFilters.exclude[MissingFieldProblem]("scala.collection.immutable.Map#Map2.serialVersionUID")
ProblemFilters.exclude[MissingFieldProblem]("scala.collection.immutable.Map#Map3.serialVersionUID")
ProblemFilters.exclude[MissingFieldProblem]("scala.collection.immutable.Map#Map4.serialVersionUID") and the build should go green again. You can verify this locally by running Unrelatedly, the file |
@hrhino And again - thank you for detailed explanation :) Will definitely read Will add these (and I already rebased my branch to have new tests before any changes to the code. The reason is that I thought it would be easier for reviewer to verify that these serialization tests are formed before any changes to serialized classes and therefore changes that pass tests too are really compatible. So I kept multiple commits intentionally to simplify code review in hope that maintainer will use 'squash and merge' button (https://help.github.com/articles/merging-a-pull-request/). |
The JVM serialization code doesn't care either way, and leaving them as public leads to annoying (but mostly harmless) MiMa errors if the annotation is added. Since the generated field is synthetic, it can only be referenced from Java, so privatizing it is unlikely to break anyone's use of it, or so I'd hope. See scala#6101 and scala#6138 for examples of places where this has caused troubles before.
The JVM serialization code doesn't care either way, and leaving them as public leads to annoying (but mostly harmless) MiMa errors if the annotation is added. Since the generated field is synthetic, it can only be referenced from Java, so privatizing it is unlikely to break anyone's use of it, or so I'd hope. See scala#6101 and scala#6138 for examples of places where this has caused troubles before. Also, because the diff was too small otherwise, have a warning for putting the annotation where it cannot possibly do any good. No one asked for it but me, but maybe it'll save someone's skin, at some time in the future.
review @Ichoran |
@id-ilych - I want to run some quick microbenchmarks to make sure that multiple dispatch on these cases doesn't eat up more time on some reasonable use-cases than it saves by providing these options. Ping me in a couple days if I haven't gotten around to it (I've probably just forgotten). |
@Ichoran Hi! How is it going? |
@Ichoran ping |
@Ichoran Is there anybody there? 😕 |
@id-ilych - Sorry! I will try to get to it tomorrow or over the weekend. (I did forget; I apologize. And then was too busy.) |
@Ichoran Hi! Any news? |
On a related note, it might be worth exploring simply getting rid of Map2/Map3/Map4, Guava had to do something similar to avoid the cost of megamorphic dispatch: google/guava#1268 |
@id-ilych - I am sorry; I'm far too overcommitted. I have to finish up some work for the strawman collections (that I didn't quite get done over the weekend), and then I'll do this as soon as I can. |
@Ichoran No problem. I'm in no hurry. Just wanted to be sure this PR is not forgotten. Will ping you again in two weeks then. No to be too annoying :) |
@Ichoran Hi! Any news? |
Sorry, haven't had time. Various time-critical things came up (both work-related and not) and some are still not resolved. Realistically it'll probably be another week at the earliest. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM, in particular the changes to test that this is serialization compatible with 2.12.4
thanks @id-ilych for the fix, and for your patience. |
I'm not sure if tests are needed and where to put them if they are...