Skip to content
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

immutable.HashMap: Investigate if keeping the kv pair in HashMap1 is worth it #8108

Closed
scabug opened this issue Dec 29, 2013 · 4 comments
Closed

Comments

@scabug
Copy link

scabug commented Dec 29, 2013

HashMap.HashMap1 lazily initializes and then caches the key value pair kv. So it keeps redundant information, presumably to avoid creating key value pairs when repeatedly iterating over all elements.

From my experience, short-lived objects are very cheap on the JVM while long-lived objects come with a larger penalty. In addition, keeping redundant information significantly complicates the code and has the potential to become inconsistent, which has already happened in this case.

So it should be investigated if it is really worth it to keep kv around, or if the code could be simplified by either

  • removing kv and creating it on demand
  • storing just kv and getting key and value from kv when needed
@scabug
Copy link
Author

scabug commented Dec 29, 2013

Imported From: https://issues.scala-lang.org/browse/SI-8108?orig=1
Reporter: @rklaehn
Affected Versions: 2.11.0-M7
See #5879

@scabug
Copy link
Author

scabug commented Dec 29, 2013

@rklaehn said:
Bugs like #5879 would be impossible without the redundant data key, value, kv.

@SethTisue
Copy link
Member

@scala/collections is this ticket still applicable in the current collections?

@som-snytt
Copy link

#11077 may be deemed a proper follow-up to the linked ticket on merged, namely, that the new implementation is efficient and free of brittle redundancy.

#12400 remains as a caution to anyone attempting to open wormy cans.

Closing as unplanned (stale) with respect to 2.12.

@som-snytt som-snytt closed this as not planned Won't fix, can't repro, duplicate, stale Aug 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants