Skip to content

Conversation

@cmelchior
Copy link
Contributor

@cmelchior cmelchior commented Oct 10, 2017

This PR fixes some of the issues found in #5391

3.7.2 - Nexus 6P
1445
1397
1345
1350
1359
Avg: 1379

4.0.0-SNAPSHOT with proxy class fixes
1129
1067
1054
973
1030
Avg: 1051
Savings ~25%

4.0.0-SNAPSHOT with proxy/mediator fixes
1115
974
939
937
950
Avg: 983
Savings ~ 29%

4.0.0-SNAPSHOT with no-alloc/proxy/mediator fixes
988
944
966
959
997
Avg: 971
Savings ~ 30%

1 second to open a Realm still feels like too much though, but this was just low hanging fruits.

writer.emitStatement(
"OsObjectSchemaInfo.Builder builder = new OsObjectSchemaInfo.Builder(\"%s\")", this.simpleClassName);
"OsObjectSchemaInfo.Builder builder = new OsObjectSchemaInfo.Builder(\"%s\", %s, %s)",
this.simpleClassName, persistedFields, computedFields);
Copy link
Contributor

@Zhuinden Zhuinden Oct 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have this weird idea that you could probably just pass in the metadata as is, that way you wouldn't need to directly pass ints as parameters to the constructor.

Unless of course that is not possible because of below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not entirely sure what you mean? OsObjectSchemaInfo.Builder contains two internal arrays. You mean that those should be constructed outside and then parsed in?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually never mind, there's a lot more to do with these sizes than I thought (JNI)

Copy link
Contributor

@beeender beeender left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are some more improvements can be done, i will make an other PR. But shall we merge this to releases branch??

@cmelchior
Copy link
Contributor Author

Next release is going to be from master anyway. Okay if I just keep it here?

@beeender
Copy link
Contributor

Yeah, master is fine to me

long propertyPtr = Property.nativeCreatePersistedProperty(name,
Property.convertFromRealmFieldType(type, isRequired), isPrimaryKey, isIndexed);
persistedPropertyPtrArray[persistedPropertyPtrCurPos] = propertyPtr;
persistedPropertyPtrCurPos++;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not persistedPropertyPtrArray[persistedPropertyPtrCurPos++] = propertyPtr;

Copy link
Contributor

@beeender beeender Oct 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer this way since i always have problems to understand the operator priority :P

persistedPropertyList.add(property);
long propertyPtr = Property.nativeCreatePersistedProperty(name,
Property.convertFromRealmFieldType(type, isRequired), !Property.PRIMARY_KEY, !Property.INDEXED);
persistedPropertyPtrArray[persistedPropertyPtrCurPos] = propertyPtr;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

if (prop->is_primary) {
object_schema.primary_key = prop->name;
}
object_schema.persisted_properties.emplace_back(std::move(*prop));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@beeender I assume the container will free the dynamically allocated pointer when destructed (since it took ownership of the pointer when using the move ctor)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uh, no. the container will "empty" the Property&& which is *prop here. That means after this line, the prop is still a valid pointer which stores an empty Property.
The memory of the empty Property(pointed by prop) will be freed at line 76.
It will be easy to understand in this way i think:

Property& prop_ref = *prop; // nothing is alloced here
object_schema.persisted_properties.emplace_back(std::move(prop_ref)); 
// prop_ref has been "emptied" by the move constructor
// but it is still a valid ref since prop is still a valid pointer.

@cmelchior cmelchior merged commit 2cfc1ec into master Oct 12, 2017
@cmelchior cmelchior deleted the cm/bug/avoid-arraycopy-during-schema-init branch October 12, 2017 18:34
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants