@here is there any performance difference between ...
# android
k
@here is there any performance difference between DataBinding / ViewBinding and Kotlin Synthetics ?
b
Yes, kotlin synthetics is backed by hashmap (or sparse array), so lookup happens each time you're accessing the view. VB just generates a class with a field per view. On the other hand KS is lazy, so findViewBindId will be called for each view separately at the first access time. VB calls findViewById for all views immediately at the binding creation time.
đź‘Ť 1
So performance difference heavily depends on your usecase, but VB should be faster in general
k
Thanks @bezrukov
g
Kotlin Synthetic are deprecated, whatever it’s faster or not it’s probably not a good idea to use them
b
Since when @gildor?
g
sorry, you right, only Anko was deprected, before it was under the same project, now it’s just android-extensions gradle plugin But I still think use Kotlin Synthetic is a bad idea
and Google Doesn’t plan to develop it too, it clearly under maintanance, and removed from all Google samples were it was uysed
Android team invest into ViewBindings
and VB has many advantages
And such 2 year old issues make them completely useless for any project with more than 2 modules https://youtrack.jetbrains.com/issue/KT-22430
k
Also, what about Data Binding v/s VB ? Should we use Databinding ?
g
It’s much more complex question. If your goal is to replace findViewById and be more type safe when you work layouts, just use VB, they are faster to compile DataBinding work with views is just a side effect, main feature is binding you data to XML layout directly and generate this glue code for you
k
To be more specific, what would be the best approach for scenarios in DataBinding vs ViewBinding 1. Where we use <include> layouts and 2. Where we use some recycler views/ custom View Classes. Thanks in advance ! 🙂
g
not sure that I got your question
DataBinding makes sense only if you want to use MVVM architecture and use all their features