In the `1.3.70` release notes for kotlin native (<...
# kotlin-native
r
In the
1.3.70
release notes for kotlin native (https://github.com/JetBrains/kotlin-native/blob/master/CHANGELOG.md), there is an entry that piqued my interest:
On-stack allocation using local escape analysis (GH-3625)
. Can anyone from the KN team elaborate more on this? (maybe @olonho?)
s
Escape analysis is an optimization that allows compiler to automatically allocate objects on stack instead of heap in some cases. Current implementation is pretty basic and works only for primitive arrays (like
IntArray
). For example,
array
here will be allocated on stack. https://github.com/JetBrains/kotlin-native/blob/4fd2e67d68c0a338a3016184377fc02cc2cac7b8/performance/ring/src/main/kotlin/org/jetbrains/ring/LocalObjectsBenchmark.kt#L25
n
What are the main use cases for this optimisation?
r
@sergey.bogolepov is there a plan to extend that to support
CValue<T>
as well?
s
Well, runtime performance :) For example, stack allocation is much cheaper than heap allocation. More advanced and sophisticated implementations of escape analysis work with pretty much any arbitrary objects.
n
Does that include Strings?
s
@raniejade, we will continue to improve this optimization to support more cases, but can’t give you any ETA because compiler optimization is a really tricky thing :) @napperley, currently, no.
r
Totally understandable, it is nice to see something is being done for improving performance. Out of curiosity, how does the conversion from a c struct value into a
CValue
work? From what I understand the value is copied from the stack into kotlin's "managed memory" right?