Search code examples
androiddatabase-performanceobjectbox

Performance penalty of ObjectBox assignable ids


ObjectBox docs suggest to use auto-assignable long ids for elements and it even has some checks based on it:

By default object IDs are assigned by ObjectBox. For each new object, ObjectBox will assign an unused ID that is above the current highest ID value used in a box. For example, if there are two objects with ID 1 and ID 100 in a box the next object that is put will be assigned ID 101.

http://objectbox.io/documentation/introduction/#Object_ID_assignment

If we have a custom key, we can add @Id(assignable = true) and it will use given field as an id.

However, I read somewhere that it adds some performance overhead and it is better to use the standard auto incremented ones whenever possible. I can't find the source now, so does anybody know if it is ok to use assignable ids for often changed objects? In addition, does ObjectBox use equals() and hashCode() somehow?

The main reasoning for using assignable ids for us is to be able to put elements using their natural long ids without manual resolving the mapping.


Solution

  • As I understood according to official docs and comment of Marcus Junginger (CTO of ObjectBox), there is no performance penalty when you use assignable ids.