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

Optimize HashPMap.get and other operations: do not create unnecessary iterator instances #41

Closed
wants to merge 4 commits into from

Conversation

udalov
Copy link

@udalov udalov commented Aug 15, 2016

We use PCollections as an internal cache for classes in Kotlin reflection library (proof) and have recently found a problem: HashPMap.get seems to create lots of unnecessary ConsPStack$1 objects, which are ConsPStack iterators, even on simple get access! Here's the original report (never mind my misleading answer there):
http://stackoverflow.com/questions/34214290/kotlin-massive-amounts-of-conspstack-how-can-i-avoid/34214718#34214718

This pull request optimizes iteration over ConsPStack inside HashPMap. First, I've made sure only ConsPStack is used as the PSequence implementation by making the types of parameters and fields more specific. In the second commit, I've replaced the for loop with the manual iteration over the ConsPStack instance. In the last commit, I've made anonymous classes inner with meaningful names, so that one will observe a more insightful ConsPStack$Itr in the stack trace instead of ConsPStack$1.

udalov added a commit to JetBrains/kotlin that referenced this pull request Aug 17, 2016
Don't create unnecessary iterator every time in HashPMap.get (see
hrldcpr/pcollections#41). Also fix a warning and remove
misleading comment
udalov added a commit to JetBrains/kotlin that referenced this pull request Aug 26, 2016
Don't create unnecessary iterator every time in HashPMap.get (see
hrldcpr/pcollections#41). Also fix a warning and remove
misleading comment
udalov added a commit to JetBrains/kotlin that referenced this pull request Sep 5, 2016
Don't create unnecessary iterator every time in HashPMap.get (see
hrldcpr/pcollections#41). Also fix a warning and remove
misleading comment
udalov added a commit to JetBrains/kotlin that referenced this pull request Sep 5, 2016
Don't create unnecessary iterator every time in HashPMap.get (see
hrldcpr/pcollections#41). Also fix a warning and remove
misleading comment
udalov added a commit to JetBrains/kotlin that referenced this pull request Sep 5, 2016
Don't create unnecessary iterator every time in HashPMap.get (see
hrldcpr/pcollections#41). Also fix a warning and remove
misleading comment

(cherry picked from commit f4a1aa6)
@hrldcpr hrldcpr force-pushed the master branch 2 times, most recently from 1daafae to c9c4c3d Compare September 16, 2022 02:22
@udalov udalov closed this Oct 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants