phetsims / tangible

Library for handling tangible input for PhET Simulations.
MIT License
0 stars 2 forks source link

Compress mediaPipeDependencies.js #12

Open zepumph opened 2 years ago

zepumph commented 2 years ago

From #9

zepumph commented 2 years ago

Compressing the js file in windows, here are the results. We get about 50% compression:

image

Using pako though, with this patch, the js file actually doubles in size:

Index: lib/mediaPipe/hands@0.4.1646424915/createMediaPipeDependencies.js
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/lib/mediaPipe/hands@0.4.1646424915/createMediaPipeDependencies.js b/lib/mediaPipe/hands@0.4.1646424915/createMediaPipeDependencies.js
--- a/lib/mediaPipe/hands@0.4.1646424915/createMediaPipeDependencies.js (revision 7c1d7794c3dd2c7463a5584862202168d5282903)
+++ b/lib/mediaPipe/hands@0.4.1646424915/createMediaPipeDependencies.js (date 1653684607769)
@@ -12,6 +12,7 @@

 const fs = require( 'fs' );
 const axios = require( 'axios' );
+const pako = require( '../../pako-2.0.3/pako-2.0.3.min.js' );

 const HANDS_VERSION = '0.4.1646424915';

@@ -50,7 +51,7 @@

       fs.writeFileSync( './mediaPipeDependencies.js', `

-  window.mediaPipeDependencies = ${JSON.stringify( mediaPipeDependencies, null, 2 )};
+  window.mediaPipeDependencies = ${JSON.stringify( { compressed: Array.from( pako.deflate( JSON.stringify( mediaPipeDependencies ) ) ) } )};
   ` );
     }
   };

I will investigate some other ways to store the data before it is time for use.

zepumph commented 2 years ago

I'm not really understanding this, we should be able to get the data cut in half. Perhaps it is something about javascript strings/arrays.I'll have to come back to this.