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

sample update / overlay recoloring performance optimization #5247

Merged
merged 7 commits into from
Dec 17, 2024

Conversation

sashankaryal
Copy link
Contributor

@sashankaryal sashankaryal commented Dec 9, 2024

What changes are proposed in this pull request?

This PR makes sample update / overlay recoloring faster, by:

  1. cleaning up existing label bitmaps to prevent memory leaks during sample update, and
  2. transferring ownership of targets array buffer to the worker (realloc) during sample update to avoid expensive copying operation

2024-12-09 18 53 11

How is this patch tested? If it is not, please explain why.

Locally. I used the following code snippet:

import fiftyone as fo
import fiftyone.zoo as foz
import numpy as np
from PIL import Image
import tempfile

UINT8_MAX = 2**8 - 1
UINT16_MAX = 2**16 - 1

def get_mask(height, width, dtype=np.uint8):
    if dtype == np.uint8:
        return np.random.binomial(1, 0.7, size=(height, width)).astype(np.uint8) * 255
    elif dtype == np.uint16:
        return np.random.binomial(1, 0.7, size=(height, width)).astype(np.uint16) * 65535
    else:
        raise Exception("dtype not supported")

def get_mask_path_from_mask(mask):
    img = Image.fromarray(mask)
    mask_path = tempfile.mktemp(".png")
    img.save(mask_path)
    return mask_path

try:
    fo.delete_dataset("detection_mask_path")
except:
    pass

dataset = foz.load_zoo_dataset("quickstart", dataset_name="detection_mask_path", persistent=True)

samples = dataset.take(len(dataset))
# multiply dataset n fold
for _ in range(3):
    dataset.add_samples(samples.clone())

mask = get_mask(256, 256)
for sample in dataset:
    mask_path = get_mask_path_from_mask(mask)
    gt_detections = sample.ground_truth.detections
    for detection in gt_detections:
        detection["mask"] = None
        detection["mask_path"] = mask_path
    pr_detections = sample.predictions.detections
    for detection in pr_detections:
        detection["mask"] = None
        detection["mask_path"] = mask_path
    sample.save()

Release Notes

Is this a user-facing change that should be mentioned in the release notes?

  • No. You can skip the rest of this section.
  • Yes. Give a description of this change to be included in the release
    notes for FiftyOne users.

(Details in 1-2 sentences. You can just refer to another PR with a description
if this PR is part of a larger change.)

What areas of FiftyOne does this PR affect?

  • App: FiftyOne application changes
  • Build: Build and test infrastructure changes
  • Core: Core fiftyone Python library changes
  • Documentation: FiftyOne documentation changes
  • Other

Summary by CodeRabbit

  • New Features

    • Introduced new properties for overlays, enhancing flexibility and usability.
    • Added a method for cleaning up overlays to prevent memory leaks.
  • Improvements

    • Enhanced bitmap resource management in overlay handling.
    • Simplified cleanup methods across multiple overlay classes for better efficiency.
  • Bug Fixes

    • Improved error handling during bitmap operations to ensure smoother performance.

@sashankaryal sashankaryal self-assigned this Dec 9, 2024
Copy link
Contributor

coderabbitai bot commented Dec 9, 2024

Warning

Rate limit exceeded

@sashankaryal has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 19 minutes and 17 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 4315fda and e22b56e.

📒 Files selected for processing (6)
  • app/packages/looker/src/lookers/abstract.ts (5 hunks)
  • app/packages/looker/src/overlays/base.ts (2 hunks)
  • app/packages/looker/src/overlays/detection.ts (1 hunks)
  • app/packages/looker/src/overlays/heatmap.ts (2 hunks)
  • app/packages/looker/src/overlays/segmentation.ts (2 hunks)
  • app/packages/looker/src/worker/disk-overlay-decoder.ts (1 hunks)

Walkthrough

The changes in this pull request focus on enhancing the AbstractLooker class and related overlay components within the Looker application. Key modifications include updating method signatures to improve memory management through the transfer of ArrayBuffer objects, introducing new methods for overlay cleanup, and simplifying existing methods for better efficiency. Additionally, properties in overlay classes have been adjusted for improved accessibility and encapsulation. These updates aim to optimize the handling of overlays and resource management.

Changes

File Path Change Summary
app/packages/looker/src/lookers/abstract.ts - Updated loadSample method to accept an additional transfer parameter.
- Modified updateSample to collect ArrayBuffer instances.
- Added cleanOverlays method.
- Improved error handling in loadSample for DataCloneError.
- Added import for LabelMask.
app/packages/looker/src/overlays/base.ts - Added closedBitmapDims property to LabelMask type.
- Introduced optional label property in Overlay interface.
- Changed label in CoordinateOverlay from protected to readonly.
app/packages/looker/src/overlays/detection.ts - Simplified cleanup method using optional chaining for bitmap cleanup.
app/packages/looker/src/overlays/heatmap.ts - Changed label property from private to public readonly.
- Simplified cleanup method using optional chaining.
app/packages/looker/src/overlays/segmentation.ts - Changed label property from private to public readonly.
- Simplified cleanup method using optional chaining.
app/packages/looker/src/worker/disk-overlay-decoder.ts - Added logic to manage bitmap resources in decodeOverlayOnDisk function, ensuring proper disposal before re-initialization.

Possibly related PRs

Suggested labels

app, bug

Suggested reviewers

  • ritch
  • benjaminpkane
  • lanzhenw

🐇 In the land of code, where bunnies dwell,
Changes were made, oh so swell!
With overlays cleaned and buffers in tow,
Memory leaks now, they won't grow!
So hop along, let’s celebrate,
For smoother lookers, we can’t wait! 🐇


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Experiment)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@sashankaryal sashankaryal requested review from a team and removed request for benjaminpkane December 9, 2024 20:33
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (5)
app/packages/looker/src/overlays/base.ts (2)

45-45: Consider documenting the new closedBitmapDims property in LabelMask

Adding the closedBitmapDims property enhances the management of bitmap dimensions. Ensure this property is well-documented and consistently used across all relevant code to prevent confusion and maintain code clarity.


87-87: Reconsider changing label from protected to readonly

Changing label from protected to readonly in the CoordinateOverlay class increases its visibility from subclasses to all external code. This may expose internal implementation details and break encapsulation. Unless there is a strong need for label to be publicly accessible, consider keeping it protected to maintain proper encapsulation.

app/packages/looker/src/overlays/heatmap.ts (1)

42-42: Reconsider changing label from private to readonly

Changing label from private to readonly in the HeatmapOverlay class increases its visibility from within the class to all external code. This may expose internal data structures and compromise encapsulation. Unless necessary, consider keeping label private to maintain proper encapsulation and information hiding.

app/packages/looker/src/overlays/segmentation.ts (1)

269-271: Remove redundant optional chaining

The optional chaining operator (?.) on line 271 is redundant since we're already inside an if block that checks for this.label.mask?.bitmap.

-      this.label.mask?.bitmap.close();
-      this.label.mask.bitmap = null;
+      this.label.mask.bitmap.close();
+      this.label.mask.bitmap = null;
app/packages/looker/src/overlays/detection.ts (1)

269-271: Remove redundant optional chaining

Similar to segmentation.ts, the optional chaining operator is redundant here since we're inside an if block that checks for bitmap existence.

-      this.label.mask?.bitmap.close();
-      this.label.mask.bitmap = null;
+      this.label.mask.bitmap.close();
+      this.label.mask.bitmap = null;
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between ea8b36f and 0e36bc0.

📒 Files selected for processing (6)
  • app/packages/looker/src/lookers/abstract.ts (4 hunks)
  • app/packages/looker/src/overlays/base.ts (3 hunks)
  • app/packages/looker/src/overlays/detection.ts (1 hunks)
  • app/packages/looker/src/overlays/heatmap.ts (2 hunks)
  • app/packages/looker/src/overlays/segmentation.ts (2 hunks)
  • app/packages/looker/src/worker/disk-overlay-decoder.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
app/packages/looker/src/overlays/heatmap.ts (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

app/packages/looker/src/overlays/segmentation.ts (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

app/packages/looker/src/worker/disk-overlay-decoder.ts (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

app/packages/looker/src/overlays/base.ts (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

app/packages/looker/src/overlays/detection.ts (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

app/packages/looker/src/lookers/abstract.ts (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

🔇 Additional comments (8)
app/packages/looker/src/lookers/abstract.ts (2)

Line range hint 723-758: Confirm that transfer parameter usage is consistent

In the updated loadSample method, ensure that all calls to postMessage correctly include the transfer parameter when transferring ArrayBuffer objects. This guarantees that the buffers are efficiently transferred without copying.


518-540: ⚠️ Potential issue

Ensure ArrayBuffers are not accessed after being transferred to the worker

When transferring ArrayBuffer objects to a worker using postMessage with the transfer parameter, the main thread loses ownership of these buffers. Ensure that after transferring, the overlayData.data.buffer and related buffers are not accessed or used in the main thread to prevent potential errors due to detached buffers.

Run the following script to verify that overlayData.data.buffer and related buffers are not used after being transferred:

✅ Verification successful

Let me gather more information about how loadSample handles these buffers and where they might be used.


Let me check how the worker communication is implemented and where these buffers are used in the worker context.


Let me check one final thing about the worker communication and buffer transfer.


Buffer transfer implementation is correct and safe

The code correctly handles the transfer of ArrayBuffers to the worker:

  1. The buffers are collected into arrayBuffers array and immediately passed to loadSample(sample, arrayBuffers) as transfer list
  2. The loadSample method properly transfers these buffers to the worker via postMessage (as seen in the implementation)
  3. After transfer, the code doesn't attempt to access the transferred buffers again
  4. The worker side (in deserializer.ts) correctly handles the received buffers

The cleanup of overlays before transfer and the immediate passing of buffers to the worker ensures there's no risk of accessing detached buffers.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for any usage of `overlayData.data.buffer` after transfer.

rg 'overlayData\.data\.buffer' --context 5

Length of output: 1595


Script:

#!/bin/bash
# Search for loadSample implementation and its usage of arrayBuffers
ast-grep --pattern 'loadSample($$$) {
  $$$
}'

# Also search for any direct references to these buffers
rg "arrayBuffers" -A 5

Length of output: 1233


Script:

#!/bin/bash
# Search for worker-related code and postMessage usage
rg "postMessage" -A 5

# Also check for any other references to these buffers in the worker
rg "transfer" --type typescript -A 5

Length of output: 19438


Script:

#!/bin/bash
# Search for loadSample implementation and any transfer-related code
rg -t ts "loadSample.*transfer|transferList" -A 5

# Also check the worker file for buffer handling
rg -t ts "data\.buffer" -A 5

Length of output: 4211

app/packages/looker/src/overlays/base.ts (1)

71-71: ⚠️ Potential issue

Ensure optional label property is handled safely in Overlay interface

By adding label?: BaseLabel; to the Overlay interface and making it optional, ensure that all implementations and usages of overlay.label properly handle the possibility that label may be undefined, to avoid potential runtime errors.

Run the following script to find usages of overlay.label that may not handle undefined:

✅ Verification successful

Optional label property is safely handled in the codebase

The code in abstract.ts shows proper handling of the optional label property through type-guard checks:

  • Uses "mask" in overlay.label and "map" in overlay.label checks before accessing properties
  • These checks implicitly ensure label exists before attempting to access its properties
  • The implementation follows TypeScript's type safety patterns for optional properties
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find usages of `overlay.label` without null checks.

rg 'overlay\.label\b' --files-with-matches | xargs -I {} rg -n 'overlay\.label\b(?!\s*\?)' {}

Length of output: 344


Script:

#!/bin/bash
# First, let's find all files that contain 'overlay.label'
rg -l 'overlay\.label'

# Then, let's see the actual usage context with surrounding lines
rg -C 3 'overlay\.label'

# Additionally, let's look for BaseLabel type definition and its usage
ast-grep --pattern 'interface BaseLabel {
  $$$
}'

# And find where Overlay interface is implemented
ast-grep --pattern 'class $_ implements Overlay {
  $$$
}'

Length of output: 1299

app/packages/looker/src/worker/disk-overlay-decoder.ts (1)

59-63: LGTM!

The update correctly checks for closedBitmapDims before accessing its properties, ensuring safe handling of bitmap dimensions when re-initializing the mask image.

app/packages/looker/src/overlays/heatmap.ts (1)

211-218: Ensure proper cleanup and reuse of bitmap dimensions

In the cleanup method, you store the bitmap's dimensions in closedBitmapDims before closing the bitmap and setting it to null. This preserves the dimensions for future use and prevents memory leaks. The implementation appears correct and effectively manages bitmap resources.

app/packages/looker/src/overlays/segmentation.ts (2)

33-33: LGTM: Good use of readonly modifier

The change from private to public readonly maintains immutability while allowing direct access, which can improve performance by eliminating the need for getter methods.


266-273: LGTM: Good performance optimization

Storing bitmap dimensions before cleanup is a good optimization as it prevents the need to recalculate these values later.

app/packages/looker/src/overlays/detection.ts (1)

266-273: LGTM: Consistent implementation across overlay types

The bitmap dimension storage optimization is consistently implemented across overlay types, which is good for maintainability and performance.

@sashankaryal sashankaryal changed the title labels recoloring performance optimization sample update / labels recoloring performance optimization Dec 9, 2024
@sashankaryal sashankaryal changed the title sample update / labels recoloring performance optimization sample update / overlay recoloring performance optimization Dec 9, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (1)
app/packages/looker/src/lookers/abstract.ts (1)

559-559: Unnecessary Use of .flat() on arrayBuffers

The arrayBuffers variable is already a flat array of ArrayBuffer, so calling .flat() is unnecessary.

You can remove the .flat() call to simplify the code:

-        this.loadSample(sample, arrayBuffers.flat());
+        this.loadSample(sample, arrayBuffers);
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 5c8d245 and 4656bdb.

📒 Files selected for processing (1)
  • app/packages/looker/src/lookers/abstract.ts (5 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
app/packages/looker/src/lookers/abstract.ts (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

🔇 Additional comments (2)
app/packages/looker/src/lookers/abstract.ts (2)

26-26: Import Statement Added Correctly

The import of LabelMask and CONTAINS from "../overlays/base" is appropriate and necessary for the updated functionality.


Line range hint 742-787: Robust Error Handling in Worker Communication

The try-catch block in the loadSample method effectively handles DataCloneError exceptions by retrying the postMessage without transferring buffers. This approach ensures the application remains robust and continues functioning even if a buffer is unexpectedly detached.

app/packages/looker/src/lookers/abstract.ts Show resolved Hide resolved
// we'll transfer that to the worker instead of copying it
const arrayBuffers: ArrayBuffer[] = [];

for (const overlay of this.pluckedOverlays ?? []) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think sampleOverlays should be used here. pluckedOverlays contains the current frame overlays, and that is handled separately in VideoLooker.updateSample

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, should we consider doing this after the new overlays are returned? It seems like this leaves the current masks in an unusable state while we wait for the new ones

Copy link
Contributor Author

@sashankaryal sashankaryal Dec 12, 2024

Choose a reason for hiding this comment

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

Yeah... although we'd have to copy the bitmaps to the worker and I'd much rather avoid that. In my next PR, where I'll be working on async overlay loading, we'll be adding a "loading" state, maybe that'll make it better?

edit: see new commits and comment

Comment on lines 330 to 332
if (!sample) {
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: comment for this return

Copy link
Contributor Author

@sashankaryal sashankaryal Dec 12, 2024

Choose a reason for hiding this comment

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

removed it. had added it previously when debugging a race condition

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
app/packages/looker/src/lookers/abstract.ts (2)

537-552: Consider enhancing detached buffer detection

The current implementation has a potential edge case in older browsers where detached buffers might have non-zero byteLength. Consider using a try-catch approach for more reliable detection.

-if (typeof buffer.detached !== "undefined") {
-  if (buffer.detached) {
-    return;
-  } else {
-    arrayBuffers.push(buffer);
-  }
-} else if (buffer.byteLength) {
-  arrayBuffers.push(buffer);
-}
+try {
+  if (buffer.byteLength === 0) {
+    continue;
+  }
+  arrayBuffers.push(buffer);
+} catch (e) {
+  // Buffer is detached
+  return;
+}

738-742: Add defensive programming measures

Consider adding null checks and error handling to prevent crashes if cleanup fails for an overlay.

 protected cleanOverlays() {
   for (const overlay of this.sampleOverlays ?? []) {
-    overlay.cleanup();
+    try {
+      overlay?.cleanup?.();
+    } catch (error) {
+      console.warn('Failed to cleanup overlay:', error);
+    }
   }
 }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4656bdb and 19fb643.

📒 Files selected for processing (5)
  • app/packages/looker/src/lookers/abstract.ts (5 hunks)
  • app/packages/looker/src/overlays/detection.ts (1 hunks)
  • app/packages/looker/src/overlays/heatmap.ts (2 hunks)
  • app/packages/looker/src/overlays/segmentation.ts (2 hunks)
  • app/packages/looker/src/worker/disk-overlay-decoder.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • app/packages/looker/src/overlays/heatmap.ts
  • app/packages/looker/src/overlays/segmentation.ts
  • app/packages/looker/src/worker/disk-overlay-decoder.ts
  • app/packages/looker/src/overlays/detection.ts
🧰 Additional context used
📓 Path-based instructions (1)
app/packages/looker/src/lookers/abstract.ts (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

🔇 Additional comments (4)
app/packages/looker/src/lookers/abstract.ts (4)

26-26: LGTM: Import addition aligns with new type usage

The addition of LabelMask import is necessary for the type annotations in the sample update logic.


518-521: LGTM: Efficient buffer collection optimization

Collection of array buffers for transfer to worker prevents unnecessary copying of large data structures.


751-753: LGTM: Proper cleanup prevents memory leaks

Cleaning up old overlays before painting new ones effectively prevents memory leaks from dangling ImageBitmaps.


781-792: LGTM: Robust error handling for buffer transfer

The implementation gracefully handles DataCloneError by falling back to copying buffers when transfer fails.

@sashankaryal
Copy link
Contributor Author

sashankaryal commented Dec 12, 2024

@benjaminpkane In the latest commits, I made it so that we retain the bitmaps and clean them in worker callback. However, mask targets will be transferred, and so super super rare edge case where user wants to know mask target value when sample is processing (hover on segmentation overlay), they might not see anything. I think it's an acceptable compromise.

I might reconsider cleaning overalys in updateSample() and not in the worker callback after we introduce more async UI stuff, but later.

@sashankaryal sashankaryal changed the base branch from develop to release/v1.2.0 December 12, 2024 22:54
@sashankaryal sashankaryal force-pushed the fix/transfer-bitmaps-back branch from 5eac87b to 4315fda Compare December 12, 2024 22:54
@sashankaryal sashankaryal force-pushed the fix/transfer-bitmaps-back branch from 4315fda to e22b56e Compare December 12, 2024 22:56
@@ -67,6 +67,7 @@ export interface Overlay<State extends Partial<BaseState>> {
draw(ctx: CanvasRenderingContext2D, state: State): void;
isShown(state: Readonly<State>): boolean;
field?: string;
label?: BaseLabel;
Copy link
Contributor

@benjaminpkane benjaminpkane Dec 16, 2024

Choose a reason for hiding this comment

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

This is not true for Classifications. Is the CoordinateOverlay type sufficient for the purpose of this PR?

Suggested change
label?: BaseLabel;

Comment on lines +785 to +786
// if one of the buffers is detached and we didn't catch it
// try again without transferring the buffers (copying them)
Copy link
Contributor

@benjaminpkane benjaminpkane Dec 16, 2024

Choose a reason for hiding this comment

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

Is guaranteeing no DataCloneError errors possible? How does a bitmap on the main thread get detached before being transferred?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I see this is mentioned in AbstractLooker.loadSample

@sashankaryal sashankaryal merged commit 35f15b2 into release/v1.2.0 Dec 17, 2024
12 checks passed
@sashankaryal sashankaryal deleted the fix/transfer-bitmaps-back branch December 17, 2024 13:52
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

Successfully merging this pull request may close these issues.

2 participants