realm-js: Writing performance regression in 10.12
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
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 17 (8 by maintainers)
@kneth FYI, here’s the same benchmark as in my previous comment, this time running
11.0.0-rc.0:So it seems the performance has degraded a little again since
v10.18.0.@AdamGerthel We are working on https://github.com/realm/realm-js/pull/4630 which is required before releasing.
@AdamGerthel Thank you for the update.
Likely later this week.
Realm Core v12.0.0 has been released with a partial fix of this regression. We will release a version soon.
We’re having the exact same issue (only on iOS). I created https://github.com/AdamGerthel/realmjsperformance to test it. The individual
createcalls are fast, but thewritecall 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.0is used:and here’s the test on another branch, where version
10.11.0is used:I’ve also tested
10.20.0-beta.5with Hermes enabled, but it’s the same problem there too.Good catch @somebody32 ! We will start investigating and report when we have an idea of what happened.