Uploaded image for project: 'Realm JavaScript SDK'
  1. Realm JavaScript SDK
  2. RJS-2132

Realm is slow to create object

      How frequently does the bug occur?

      Always

      Description

      Realm is really slow to create when there are millions of objects to create. I had 332,015 polygons to create and it took me 5-10 hours to finish the job. and I can confirm that the use of SphericalMercator is not time-consuming.
      My code is here
      const Realm = require("realm");
      const SphericalMercator = require("@mapbox/sphericalmercator");
      const merc = new SphericalMercator({
      {{ size: 512,}}
      {{ antimeridian: true,}}
      });
      const TaskSchema = {
      {{ name: "Polygon",}}
      {{ properties: {}}
      {{ _id: "int",}}
      {{ minX: "double",}}
      {{ minY: "double",}}
      {{ maxX: "double",}}
      {{ maxY: "double",}}
      {{ },}}
      {{ primaryKey: "_id",}}
      };
      async function main() {
      {{ var origin = [-87.096306, 40.214224];}}
      {{ var count = 0;}}
      {{ const fs = require("fs");}}
      {{ const path = require("path");}}
      {{ const directoryPath = path.join(__dirname, "realm-files");}}
      if (!fs.existsSync(directoryPath)) {
      {{ fs.mkdirSync(directoryPath);}}
      {{ }}}
      {{ const realm = await Realm.open({}}
      {{ path: "realm-files/myrealm.realm",}}
      {{ schema: [TaskSchema],}}
      {{ });}}
      {{ for (var i = 0; i < 2500; i++) {}}
      {{ if (origin[0] > -86.694305 || origin[1] > 40.563003) {}}
      {{ break;}}
      {{ }}}
      {{ for (var j = 0; j < 2500; j++) {}}
      {{ if (origin[0] > -86.694305 || origin[1] > 40.563003) {}}
      {{ console.log(origin[0]);}}
      {{ console.log();}}
      {{ break;}}
      {{ }}}
      {{ var pixelOrigin = merc.px(origin, 22);}}
      {{ const pixelDest1 = [pixelOrigin[0], pixelOrigin[1] - 1405.38];}}
      {{ const pixelDest2 = [pixelOrigin[0] + 1405.38, pixelOrigin[1] - 1405.38];}}
      {{ const pixelDest3 = [pixelOrigin[0] + 1405.38, pixelOrigin[1]];}}
      {{ const cordDest1 = merc.ll(pixelDest1, 22);}}
      {{ const cordDest2 = merc.ll(pixelDest2, 22);}}
      {{ const cordDest3 = merc.ll(pixelDest3, 22);}}
      {{ if (j == 0) {}}
      {{ iter = cordDest3;}}
      {{ } }}
      {{ realm.write(() => {}}
      {{ polygon = realm.create("Polygon", {}}
      {{ _id: count,}}
      {{ minX: origin[0],}}
      {{ minY: origin[1],}}
      {{ maxX: cordDest2[0],}}
      {{ maxY: cordDest2[1],}}
      {{ });}}
      {{ });}}
      {{ origin = cordDest1;}}
      {{ count++;}}
      {{ }}}
      {{ origin = iter;}}
      {{ }}}
      }
      (async () => {
      await main();
      })();
      `

      Stacktrace & log output

      No response

      Can you reproduce the bug?

      Always

      Reproduction Steps

      When I run my program, after writing it 10,000 times, it gets slower.

      Version

      11.4.0

      What services are you using?

      Local Database only

      Are you using encryption?

      No

      Platform OS and version(s)

      Windows 11, and newest node.js

      Build environment

      No response

      Cocoapods version

      No response

            Assignee:
            Unassigned Unassigned
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: