-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Ignore same values when using copyToRealm #6224
Conversation
return BinaryData(); | ||
|
||
auto& value = any_cast<OwnedBinaryData&>(v); | ||
const auto& data = value.get(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this safe?
# Conflicts: # CHANGELOG.md # realm/realm-library/src/main/cpp/util.cpp
Ready for review @nhachicha @kneth |
realm/realm-library/src/main/cpp/io_realm_internal_objectstore_OsObjectBuilder.cpp
Outdated
Show resolved
Hide resolved
realm/realm-library/src/main/cpp/io_realm_internal_objectstore_OsObjectBuilder.cpp
Show resolved
Hide resolved
realm/realm-library/src/main/cpp/io_realm_internal_objectstore_OsObjectBuilder.cpp
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job ❤️ I think we need to update insertOrUpdate
even though it's faster, it's still not optimised to generate fewer SET instructions for Sync
realm/realm-library/src/main/cpp/io_realm_internal_objectstore_OsObjectBuilder.cpp
Show resolved
Hide resolved
realm/realm-library/src/main/java/io/realm/internal/objectstore/OsObjectBuilder.java
Show resolved
Hide resolved
library-benchmarks/src/androidTest/java/io/realm/benchmarks/CopyToRealmBenchmarks.java
Outdated
Show resolved
Hide resolved
realm/realm-library/src/main/java/io/realm/internal/NativeContext.java
Outdated
Show resolved
Hide resolved
realm/realm-library/src/main/java/io/realm/internal/NativeContext.java
Outdated
Show resolved
Hide resolved
All comments addressed @nhachicha. While it is true that ideally this should be added to all ways of importing data, it isn't clear it is worth the effort currently. It is, no matter what, outside the scope of this PR. I have created #6263 that tracks adding it to the rest of our API's |
Ups. Some other comments where hiding. All should be fixed now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏when CI is happy
This PR changes the implementation of
copyToRealm
to use Object StoresObject::create
method.This allows us to ignore fields with the same value. Currently this generates a lot of extra set instructions when syncing Realms which has a negative performance impact on the server.
A side-effect of this is also that using this method fine-grained notifications will not report any changes for this field. However this is only true if using
copyToRealm
orcopyToRealmOrUpdate
Implementation is done by adding a new
OsObjectBuilder
class that will build up a list of data on the C++ side before creating the whole thing. From the user API side, we have a newImportFlag
enum.Enums are being used instead of booleans or int flags since that mirros the API used by
RealmObjectSchema
for specifying field properties. It also has the upside of being more typesafe (plus I strongly suspect more flags in the future).For the first iteration only
copyToRealm/copyToRealmOrUpdate
will use this method. We should consider adding the same flags to other methods like andcreateOrUpdateFromJSon*
.insertOrUpdate
is designed to be super performant, so it is unclear if we can support ImportFlags in this method without a lot of extra effort.Performance
Performance in the new implementation is pretty much on par with the current performance. When diffing is enabled performance decrease about 20% which is unavoidable as all properties needs to be compared with what is on disk.
5.8.0
![image](https://user-images.githubusercontent.com/406066/47563512-54d28b80-d922-11e8-8a23-639dd6b3d8a4.png)
5.7.0
![image](https://user-images.githubusercontent.com/406066/47563500-497f6000-d922-11e8-8051-14985d0b0539.png)
Diffed vs. non-diffed performance in 5.8
![image](https://user-images.githubusercontent.com/406066/47563297-a9293b80-d921-11e8-80cd-bb9cbb70e11e.png)
Relevant files to review
java_object_accessor.hpp
contains the majority of the C++ codeio_realm_internal_objectstore_OsObjectBuilder.cpp
contains the JNI boundaryOsObjectBuilder
contains most of the Java code, but isn't really very interesting.TODO
OsObjectBuilder
OsObjectBuilder
OsObjectBuilder
OsObjectBuilder
DO_NOT_WRITE_SAME_VALUES
,IGNORE_SAME_VALUES
? Others.. The current choice is somewhat arbitraryJavaContext::print()
crashing on CIutil::Any
or figure another way to get performance back to normal.