realm / realm-java

Realm is a mobile database: a replacement for SQLite & ORMs
http://realm.io
Apache License 2.0
11.46k stars 1.75k forks source link

Improve performance of creating proxy object. #3444

Open zaki50 opened 8 years ago

zaki50 commented 8 years ago

To support default value feature (#777), #3397 changes the way to create the proxy instance. That introduced about 10-15% unexpected overhead for creating proxy instance.

One of the reason of performance degrade is accessing the thread local. I modified #3397 no to use thread local and it improves the performance about 7-10%.

The idea is

  1. Making a state class for each proxy class
  2. Move the proxy class to inner class of its state class
  3. Create State instance first, and then create proxy instance.

I think proxy classes can obtain object context information from its enclosing instance.

Zhuinden commented 8 years ago

This matters only in case of realm.createObject(), right?

So realmResults.get(i) is not impacted?

zaki50 commented 8 years ago

@Zhuinden Unfortunately, it affects all APIs that create proxy object.

If my idea works as expected, I think that almost all overhead will be removed.