Skip to content
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

Writing performance regression in 10.12 #4383

Closed
somebody32 opened this issue Mar 1, 2022 · 17 comments
Closed

Writing performance regression in 10.12 #4383

somebody32 opened this issue Mar 1, 2022 · 17 comments
Assignees

Comments

@somebody32
Copy link

somebody32 commented Mar 1, 2022

How frequently does the bug occur?

All the time

Description

Hi, while updating my app from 10.11 to 10.13, I found that writing times for one of the tables increased up to 20x.

While debugging, I've managed to create a reproducible example and nailed down that the first affected version is 10.12 and that having an array of strings in the schema is causing it.

The example is based on Realm's TS Example

Task.ts

class Task {
  static generate(id) {
    return {
      id: id.toString(),
      triggeredOn: [
        'Monday',
        'Tuesday',
        'Wednesday',
        'Thursday',
        'Friday',
        'Saturday',
        'Sunday',
      ],
    }
  }

  static schema = {
    name: 'Task',
    primaryKey: 'id',
    properties: {
      id: 'string',
      triggeredOn: 'string[]',
    },
  };
}

export default Task;

and then the writing code:

const config = {
  schema: [Task.schema],
  deleteRealmIfMigrationNeeded: true
};
const realm = await Realm.open(config);
const start = new Date();
realm.write(() => {
  Array.from({length: 100}, (_, i) => {
    realm.create('Task', Task.generate(i), 'modified');
  });
 });
console.log('Writing Finished', new Date().getTime() - start.getTime());

For version < 10.12, I have about 1-2ms for writing, on 10.12+, it doesn't go below 23-25.

Stacktrace & log output

No response

Can you reproduce the bug?

Yes, always

Reproduction Steps

No response

Version

10.12

What SDK flavour are you using?

Local Database only

Are you using encryption?

No, not using encryption

Platform OS and version(s)

iOS 15.2

Build environment

React Native 0.67.3

Cocoapods version

No response

@takameyer
Copy link
Contributor

Good catch @somebody32 ! We will start investigating and report when we have an idea of what happened.

@kneth
Copy link
Contributor

kneth commented Mar 2, 2022

I have investigated it a bit today but haven't reached a conclusion. I have used the script:

const Realm = require("realm");

function generate(id) {
    return {
      id: id.toString(),
      triggeredOn: [
        'Monday',
        'Tuesday',
        'Wednesday',
        'Thursday',
        'Friday',
        'Saturday',
        'Sunday',
      ]
    }
};

const schema = {
    name: 'Task',
    primaryKey: 'id',
    properties: {
      id: 'string',
      triggeredOn: 'string[]',
    },
};


const config = {
  schema: [schema],
};
const realm = new Realm(config);
realm.write(() => {
  for(let i = 0; i < 2500; i++) {
    realm.create('Task', generate(i), 'modified');
  }
});
process.exit(0);

I have profiled the execution using the command:

rm -rf default.realm* && xcrun xctrace record --template 'Time Profiler' --target-stdout - --launch -- /Users/kneth/.nvm/versions/node/v16.13.0/bin/node task.js

@kneth
Copy link
Contributor

kneth commented Mar 4, 2022

I have tried different variations:

const Realm = require("realm");

const schema = {
    name: 'Task',
    primaryKey: 'id',
    properties: {
      id: 'int',
      val: "int",
    },
};


const config = {
  schema: [schema],
  _automaticChangeNotifications: false	
};
const realm = new Realm(config);
let start = new Date();
realm.write(() => {
  for(let i = 0; i < 25000; i++) {
    realm.create('Task', { id: i, val: i }, "modified");
  }
});
console.log('Writing Finished', new Date().getTime() - start.getTime());
process.exit(0);
const Realm = require("realm");

const Link = {
	name: "Link",
	properties: { 
		lid: 'int'
	}
};

const Task = {
    name: 'Task',
    primaryKey: 'id',
    properties: {
      id: 'int',
      lobj: "Link"
    },
};


const config = {
  schema: [Task, Link],
};
const realm = new Realm(config);
let start = new Date();
realm.write(() => {
  for(let i = 0; i < 25000; i++) {
    realm.create('Task', { id: i, lobj: { lid: i }}, "modified");
  }
});
console.log('Writing Finished', new Date().getTime() - start.getTime());
process.exit(0);

At least, on MacOS + node 16 I am not able to reproduce it.

@somebody32
Copy link
Author

@kneth I've discovered it on React Native and JSC, would try just on bare node

@somebody32
Copy link
Author

somebody32 commented Mar 7, 2022

@kneth I can't reproduce it on node too, looks like it's RN related only

@somebody32
Copy link
Author

Just FYI, @kneth @takameyer, tried with the latest version (10.14), but unfortunately, the problem is still there

@AdamGerthel
Copy link

AdamGerthel commented May 22, 2022

We're having the exact same issue (only on iOS). I created https://github.com/AdamGerthel/realmjsperformance to test it. The individual create calls are fast, but the write call takes ~20ms no matter if I'm saving 1 or 100 objects. My example does not use arrays, just a schema with a single string property.

Here's the test result from the main branch, where version 10.17.0 is used:

Screen Shot 2022-05-22 at 20 45 54

---

and here's the test on another branch, where version 10.11.0 is used:
Screen Shot 2022-05-22 at 20 56 08

I've also tested 10.20.0-beta.5 with Hermes enabled, but it's the same problem there too.

@somebody32
Copy link
Author

I have a hunch that this is not js/RN only related, looks like the same problem is in realm-swift around the same update (bumping realm core to 11.8.0+): realm/realm-swift#7734

@kneth
Copy link
Contributor

kneth commented May 27, 2022

Realm Core v12.0.0 has been released with a partial fix of this regression. We will release a version soon.

@AdamGerthel
Copy link

@kneth Great! Is there a way to test it before it's released? So I can verify that it fixes or at least relieves this issue

@kneth
Copy link
Contributor

kneth commented May 29, 2022

@AdamGerthel We have released v10.18.0 with the fix. I leave the issue open to give you a chance to try it out.

@AdamGerthel
Copy link

AdamGerthel commented May 29, 2022

Looking good @kneth!

Screen Shot 2022-05-29 at 12 26 19

Any idea when the beta (which includes Hermes support) will be bumped?

@kneth
Copy link
Contributor

kneth commented May 30, 2022

@AdamGerthel Thank you for the update.

Any idea when the beta (which includes Hermes support) will be bumped?

Likely later this week.

@kneth
Copy link
Contributor

kneth commented May 31, 2022

With the good news from @AdamGerthel I close the issue

@kneth kneth closed this as completed May 31, 2022
@AdamGerthel
Copy link

@kneth Any updates on when we can expect a new release of the Hermes-enabled beta?

@kneth
Copy link
Contributor

kneth commented Jun 13, 2022

@AdamGerthel We are working on #4630 which is required before releasing.

@AdamGerthel
Copy link

@kneth FYI, here's the same benchmark as in my previous comment, this time running 11.0.0-rc.0:

Screen Shot 2022-07-13 at 22 27 37

So it seems the performance has degraded a little again since v10.18.0.

@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.
Projects
None yet
Development

No branches or pull requests

4 participants