amzn / sketch-constructor

Read/write/manipulate Sketch files in Node without Sketch plugins!

Home Page:https://amzn.github.io/sketch-constructor/#/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Create "Sketch" object from extracted sketch files

Means88 opened this issue · comments

JSZip cost too much memory when I call Sketch.fromFile with a big sketch file (about 500 MB, 400+ artboards). eg:

// 1.js
const { Sketch } = require('sketch-constructor');
Sketch.fromFile('sketch/1.sketch');
$ /usr/bin/time -l node 1.js
        5.04 real         3.66 user         0.67 sys
 869953536  maximum resident set size
         0  average shared memory size
         0  average unshared data size
         0  average unshared stack size
    215393  page reclaims
         0  page faults
         0  swaps
         0  block input operations
         0  block output operations
         0  messages sent
         0  messages received
         0  signals received
         0  voluntary context switches
     14545  involuntary context switches

I got out of memory exception in my application, maybe we can extract sketch file in other ways (native unzip or something else), and read from the extracted files to save memory.

$ /usr/bin/time -l unzip sketch/1.sketch
...
        6.80 real         2.68 user         1.42 sys
   2105344  maximum resident set size
         0  average shared memory size
         0  average unshared data size
         0  average unshared stack size
       521  page reclaims
         8  page faults
         0  swaps
         0  block input operations
         0  block output operations
         0  messages sent
         0  messages received
         0  signals received
     10148  voluntary context switches
     16336  involuntary context switches

Thank you for bringing this up! I was wondering what the memory footprint of this would be for larger files, but never got around to actually testing it out.