bosonprotocol / boson-dcl

Boson Protocol - Metaverse Toolkit - Decentraland SDK
Apache License 2.0
3 stars 0 forks source link

Do not reload images that have already been loaded (reuse the same Texture instance) #34

Open levalleux-ludo opened 1 year ago

levalleux-ludo commented 1 year ago

As loading of images takes some relevant time, it's possible to cache the textures for images that have already been loaded and reuse them if user is reopening the same product details (or is just looping over the image list of the product). An exemple of such an implementation can be found in boson-dcl v1: https://github.com/bosonprotocol/boson-dcl/blob/main/src/ImageServer.ts

export class ImageServer {
  imageMap: { [key: string]: Image } = {};

  constructor() {}

  getImage(imageUrl : IImageDefinition): Image {
    const imageUrl = imageDefinition.imageUrl;
    if (this.imageMap[imageUrl]) {
      return this.imageMap[imageUrl];
    }
    const image = new Image({
      texture: new Texture(imageUrl),
      width: imageDefinition.width,
      height: imageDefinition.height,
    });
    this.imageMap[imageUrl] = image;
    return image;
  }
}
econsacro commented 1 year ago

Images load only once per kiosk, no matter how many times the user interacts.