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

Inlining for property accessors #34

Closed
abreslav opened this issue Jul 13, 2016 · 10 comments
Closed

Inlining for property accessors #34

abreslav opened this issue Jul 13, 2016 · 10 comments
Labels
Milestone

Comments

@abreslav
Copy link
Contributor

abreslav commented Jul 13, 2016

Proposal

@yole
Copy link
Contributor

yole commented Jul 13, 2016

I think the proposal lacks a motivation section. As we all know, the inline modifier for function is not a performance tool, because HotSpot does a great job of inlining (and AFAIK it has special logic for inlining property accessors). For functions, its main benefits are inlining lambda parameters and associated benefits (non-local returns), as well as reified type parameters. Neither of these are applicable to property accessors. So: why?

@Takhion
Copy link

Takhion commented Jul 14, 2016

Android, for example, benefits greatly from inlining!

@udalov
Copy link
Member

udalov commented Jul 14, 2016

For functions, its main benefits are inlining lambda parameters and associated benefits (non-local returns), as well as reified type parameters. Neither of these are applicable to property accessors.

In fact, reified type parameters will now be applicable to property accessors:

inline val <reified T : PsiElement> T.nextSiblingOfSameType: T?
    get() = PsiTreeUtil.getNextSiblingOfType(this, T::class.java)

Another motivation, as with functions, is to hide some properties from the binary interface of a library. In Kotlin standard library, together with the @InlineOnly annotation this might make it possible in the future to exclude declarations of such properties from class files, reducing method count.

@yole
Copy link
Contributor

yole commented Jul 14, 2016

Sounds great! Now let's add it to the text of the KEEP :)

@Jire
Copy link

Jire commented Jul 14, 2016

I'm very excited for reified in properties!

abreslav added a commit that referenced this issue Jul 15, 2016
* Enable `@InlineOnly` properties whose signatures can be changed without affecting the binary compatiblity of a library
* Make reified type parameters available for property accessors

#34
@abreslav abreslav added this to the 1.1 milestone Oct 10, 2016
@konsoletyper
Copy link

What about member properties? Can they be inlined in case they are neither open nor override?

@abreslav
Copy link
Contributor Author

abreslav commented Nov 7, 2016

@konsoletyper If they have no backing fields, the rules should be the same as for functions. Fields are problematic on the JVM because they are private. // cc @max-kammerer

@eygraber
Copy link

eygraber commented Dec 8, 2016

This would be nice to move an extension function I have to a property (which would make more sense as a property)

inline fun <reified T : Any?> T.TAG()
    = ((this as? Any)?.javaClass?.simpleName ?: "${T::class.simpleName ?: "null"}?").replace("CompanionObject", "")

@fab1an
Copy link

fab1an commented May 24, 2017

I found performance-critical loops using for (i in 0..list.lastIndex where JMH profiling showed the slowest method call being lastIndex

@dzharkov
Copy link
Contributor

dzharkov commented Feb 14, 2018

The feature has been released in Kotlin 1.1, thus I'm closing the KEEP. Do not hesitate to open a YouTrack issue for any additional suggestions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

9 participants