Skip to content

Commit

Permalink
feat: OPTIC-1479: Improve memory usage of Image tag
Browse files Browse the repository at this point in the history
  • Loading branch information
bmartel committed Jan 17, 2025
1 parent e0e91fd commit 840b5b9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 9 additions & 2 deletions web/libs/editor/src/tags/object/Image/ImageEntity.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { types } from "mobx-state-tree";
import { FileLoader } from "../../../utils/FileLoader";
import { clamp } from "../../../utils/utilities";
import { FF_IMAGE_MEMORY_USAGE, isFF } from "libs/editor/src/utils/feature-flags";

const fileLoader = new FileLoader();

Expand Down Expand Up @@ -67,10 +68,14 @@ export const ImageEntity = types
}))
.actions((self) => ({
preload() {
if (isFF(FF_IMAGE_MEMORY_USAGE)) {
self.setCurrentSrc(self.src);
self.setDownloaded(true);
self.setProgress(1);
return;
}
if (self.ensurePreloaded() || !self.src) return;

self.setDownloading(true);

fileLoader
.download(self.src, (_t, _l, progress) => {
self.setProgress(progress);
Expand All @@ -87,6 +92,8 @@ export const ImageEntity = types
},

ensurePreloaded() {
if (isFF(FF_IMAGE_MEMORY_USAGE)) return false;

if (fileLoader.isError(self.src)) {
self.setDownloading(false);
self.setError(true);
Expand Down
2 changes: 2 additions & 0 deletions web/libs/editor/src/utils/feature-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ export const FF_LEAP_1173 = "fflag_feat_front_leap_1173_disable_postpone_skip_sh

export const FF_PER_FIELD_COMMENTS = "fflag_feat_all_leap_1430_per_field_comments_100924_short";

export const FF_IMAGE_MEMORY_USAGE = "fflag_feat_front_optic_1479_improve_image_tag_memory_usage_short";

Object.assign(window, {
APP_SETTINGS: {
...(window.APP_SETTINGS ?? {}),
Expand Down

0 comments on commit 840b5b9

Please sign in to comment.