Tóth István Zoltán
07/10/2024, 10:55 AMa is SomeClassA
and a.isA
(performance wise).
interface SomeInterface {
val isA : Boolean
}
class SomeClassA : SomeInterface {
val isA
get() = true
}
class SomeClassB : SomeInterface {
val isA
get() = false
}
dmitriy.novozhilov
07/10/2024, 11:20 AMis
check is an iteration over the supertypes hierarchy
So property may be faster than is
check, if the hierarchy is big and SomeInterface
buried somewhere deep in it, so overhead of virtual call becomes less than this iteration
But in most cases is
will be fasterdmitriy.novozhilov
07/10/2024, 11:24 AMis
check for abstract classes checks only the line of superclasses, and for interfaces it traverses the (potentially complex) graph of interfaces
• invoke virtual on classes also faster, as there are less inherited virtual tables
Originally the whole FIR tree was interfaces (except actual implementations), and during performance investigations we discovered that this difference actually matters. After we replaced most of the hierarchy with abstract classes
, we gained about 10-15% performance boost for the frontendTóth István Zoltán
07/10/2024, 11:24 AMdmitriy.novozhilov
07/10/2024, 11:26 AMTóth István Zoltán
07/10/2024, 11:26 AMdmitriy.novozhilov
07/10/2024, 11:27 AMdmitriy.novozhilov
07/10/2024, 11:36 AMdmitriy.novozhilov
07/10/2024, 11:38 AMTóth István Zoltán
07/10/2024, 11:38 AMdmitriy.novozhilov
07/10/2024, 11:40 AMdamian
07/10/2024, 1:51 PMinvoke-interface
and invoke-virtual
) is that the position of methods in the table is (relatively) fixed when using classes (since there can only be one superclass), but for interfaces could be anywhere and thus the table needs to be searched - is that accurate and/or what you're referring to?dmitriy.novozhilov
07/10/2024, 1:52 PM