feat: implement aggressive WASM bundle size optimization (6.20% reduction) #110
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
WASM Bundle Size Optimization
This PR implements aggressive WASM bundle size optimization for libpg-query-node, achieving a 6.20% total bundle size reduction (131.09 KB reduction from 2.07 MB to 1.94 MB) while maintaining full API compatibility.
🎯 Optimization Results
🚀 Optimization Strategies Implemented
1. Aggressive Compilation Flags
-Oz: Replaced-O3with size-focused optimization--closure 1: Enabled Google Closure Compiler for advanced JavaScript minification-Wl,--gc-sections,--strip-all: Dead code elimination and symbol stripping-sFILESYSTEM=0: Removed filesystem support for additional size reduction2. Build Configuration Updates
build-optimizedandbuild-optimized-no-fs3. Size Tracking Tooling
scripts/size-report.jsfor detailed bundle analysisscripts/size-compare.jswith baseline tracking📊 Detailed Size Breakdown
The optimization achieved significant reductions across multiple areas:
WASM Binary Optimization (3.88% reduction)
-Ozflag optimized for size over speedwasm-optpost-processing with aggressive size settingsJavaScript Wrapper Optimization (89% reduction)
Build Process Enhancements
🛠 New Build Commands
✅ Verification & Testing
📈 Performance Impact
🔧 Implementation Details
The optimization maintains backward compatibility by:
buildtarget unchanged📋 Files Changed
Makefile: Added optimized build targets and compilation flagspackage.json: New build scripts for optimized builds and size trackingscripts/size-report.js: Automated bundle size reporting toolscripts/size-compare.js: Before/after size comparison utilityOPTIMIZATION_PROGRESS.md: Detailed optimization documentation and resultsLink to Devin run: https://app.devin.ai/sessions/c47cb00752b24deda9d86e51b99c9b95
Requested by: Dan Lynch ([email protected])
This optimization provides significant bundle size reduction while maintaining full functionality, making libpg-query-node more efficient for web and Node.js applications.