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

Large number of annotations lagging in the latest version #1704

Open
hamza-hajji opened this issue Oct 21, 2024 · 2 comments
Open

Large number of annotations lagging in the latest version #1704

hamza-hajji opened this issue Oct 21, 2024 · 2 comments

Comments

@hamza-hajji
Copy link
Contributor

Describe the bug
In xeokit sdk 2.6.10, rendering 200 annotations runs smoothly, in [email protected], there is significant lagging, I put two screen casts of the 200 annotations in different versions

To Reproduce
Steps to reproduce the behavior:

Render 200 annotations in [email protected]

const annotations = new AnnotationsPlugin(viewer, {
  // Default HTML template for marker position
  markerHTML:
    "<div class='annotation-marker' style='background-color: {{markerBGColor}};'>{{glyph}}</div>",

  // Default HTML template for label
  labelHTML:
    "<div class='annotation-label' style='background-color: {{labelBGColor}};'>" +
    "<div class='annotation-title'>{{title}}</div><div class='annotation-desc'>{{description}}</div></div>",

  // Default values to insert into the marker and label templates
  values: {
    markerBGColor: "red",
    labelBGColor: "red",
    glyph: "X",
    title: "Untitled",
    description: "No description",
  },
});

for (let index = 0; index < 200; index++) {
  annotations.createAnnotation({
    id: "myAnnotation" + index,
    worldPos: [Math.random() * 2, Math.random() * 2, Math.random() * 2], // 3D World-space position
    occludable: false, // Optional, default, makes Annotation invisible when occluded by Entities
    markerShown: true, // Optional, default is true, makes position visible (when not occluded)
    labelShown: false, // Optional, default is false, makes label visible (when not occluded)
    values: {
      // Optional, overrides AnnotationPlugin's defaults
      glyph: "O",
      title: "Origin",
      description: "This is my annotation.",
      markerBGColor: "blue",
    },
  });
}

200AnnotationsLag

It lags

Expected behavior
It doesn't lag, same behavior as [email protected]

ezgif-5-372170b6fa

@MichalDybizbanskiCreoox
Copy link
Collaborator

Hi @hamza-hajji, thank you for your report!

The slowdown that you observe results from the getBoundingClientRect calls (which trigger browser's layout reflows) that were used to implement Annotation::setMarkerAlign and Annotation::setLabelPosition methods, introduced by the PR at #1554

The cost of calling the getBoundingClientRect method accumulates throughout a frame, and if there's a lot of Annotations that require its computation, it really adds up.
We need to consider whether there are other ways to achieve the same result without this costly call.
One possible solution, without sacrificing the alignment feature's utility, would be an optimized code path that didn't require getBoundingClientRect, which would work for annotations with the default "left" marker alignment, and with no label.
Would this limitation cover your use case?

@hamza-hajji
Copy link
Contributor Author

which would work for annotations with the default "left" marker alignment, and with no label

@MichalDybizbanskiCreoox I don't use marker alignment, but I do set labelHTML for the annotation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants