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

[Bug] loadAndCacheImage slows down 8 times after build React app with Vite #1802

Open
MustafaEminn opened this issue Feb 3, 2025 · 2 comments

Comments

@MustafaEminn
Copy link

MustafaEminn commented Feb 3, 2025

Describe the Bug

Loading and caching 8MB MG image takes 1 second when I'm running application on my local. But same images takes 8 seconds after I built my application. I'm only using local file system not using WADORS.

vite.config.ts:

import { viteCommonjs } from '@originjs/vite-plugin-commonjs';

export default defineConfig({
  build: {
    assetsDir: 'static',
    rollupOptions: {
      context: 'window',
      moduleContext: (id) => {
        if (id.includes('pdfmake/build/vfs_fonts.js')) {
          return 'window';
        }
      },
    },
  },
  css: {
    modules: {
      generateScopedName: '[name]_[local]_[hash:base64:5]',
    },
  },
  worker: {
    format: 'es',
    rollupOptions: {
      external: ['@icr/polyseg-wasm'],
    },
  },
  optimizeDeps: {
    exclude: ['@cornerstonejs/dicom-image-loader'],
    include: ['dicom-parser'],
  },
  plugins: [
    react(),
    viteCommonjs(),
    // compression({ deleteOriginalAssets: true })
  ],
});

package.json:

    "@cornerstonejs/core": "^2.18.8",
    "@cornerstonejs/dicom-image-loader": "^2.18.8",
    "@cornerstonejs/nifti-volume-loader": "^2.18.8",
    "@cornerstonejs/tools": "^2.18.8",

Steps to Reproduce

  1. Use local file system
  2. Build react app with vite
  3. try to open a dicom image in STACK type

The current behavior

It is very slow compared to unbundled version.

The expected behavior

It would be same as unbundled version

OS

Windows 10

Node version

20.11.0

Browser

Chrome latest

@MustafaEminn MustafaEminn changed the title [Bug] loadAndCacheImage slows down 400% after build React app with Vite [Bug] loadAndCacheImage slows down 8 times after build React app with Vite Feb 3, 2025
@sedghi
Copy link
Member

sedghi commented Feb 3, 2025

Hmmm, how much of it is request over network?

@MustafaEminn
Copy link
Author

Hmmm, how much of it is request over network?

There is no request over network. Every data coming from SSD or RAM. I have debugged the problem. The time consuming part is @cornerstonejs\dicom-image-loader\dist\esm\imageLoader\createImage.js createImage function.

I'm also getting warning messages during build.

[plugin:vite:resolve] [plugin vite:resolve] Module "fs" has been externalized for browser compatibility, imported by "node_modules/@cornerstonejs/codec-libjpeg-turbo-8bit/dist/libjpegturbowasm_decode.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] [plugin vite:resolve] Module "path" has been externalized for browser compatibility, imported by "node_modules/@cornerstonejs/codec-libjpeg-turbo-8bit/dist/libjpegturbowasm_decode.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] [plugin vite:resolve] Module "fs" has been externalized for browser compatibility, imported by "node_modules/@cornerstonejs/codec-charls/dist/charlswasm_decode.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] [plugin vite:resolve] Module "path" has been externalized for browser compatibility, imported by "node_modules/@cornerstonejs/codec-charls/dist/charlswasm_decode.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] [plugin vite:resolve] Module "fs" has been externalized for browser compatibility, imported by "node_modules/@cornerstonejs/codec-openjph/dist/openjphjs.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] [plugin vite:resolve] Module "path" has been externalized for browser compatibility, imported by "node_modules/@cornerstonejs/codec-openjph/dist/openjphjs.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] [plugin vite:resolve] Module "fs" has been externalized for browser compatibility, imported by "node_modules/@cornerstonejs/codec-openjpeg/dist/openjpegwasm_decode.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] [plugin vite:resolve] Module "path" has been externalized for browser compatibility, imported by "node_modules/@cornerstonejs/codec-openjpeg/dist/openjpegwasm_decode.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] [plugin vite:resolve] Module "fs" has been externalized for browser compatibility, imported by "node_modules/@cornerstonejs/codec-libjpeg-turbo-8bit/dist/libjpegturbowasm_decode.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] [plugin vite:resolve] Module "path" has been externalized for browser compatibility, imported by "node_modules/@cornerstonejs/codec-libjpeg-turbo-8bit/dist/libjpegturbowasm_decode.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] [plugin vite:resolve] Module "fs" has been externalized for browser compatibility, imported by "node_modules/@cornerstonejs/codec-openjpeg/dist/openjpegwasm_decode.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] [plugin vite:resolve] Module "path" has been externalized for browser compatibility, imported by "node_modules/@cornerstonejs/codec-openjpeg/dist/openjpegwasm_decode.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] [plugin vite:resolve] Module "fs" has been externalized for browser compatibility, imported by "node_modules/@cornerstonejs/codec-charls/dist/charlswasm_decode.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] [plugin vite:resolve] Module "path" has been externalized for browser compatibility, imported by "node_modules/@cornerstonejs/codec-charls/dist/charlswasm_decode.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] [plugin vite:resolve] Module "fs" has been externalized for browser compatibility, imported by "node_modules/@cornerstonejs/codec-openjph/dist/openjphjs.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] [plugin vite:resolve] Module "path" has been externalized for browser compatibility, imported by "node_modules/@cornerstonejs/codec-openjph/dist/openjphjs.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.

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

No branches or pull requests

2 participants