Skip to content

Save bytes in model handling code#43

Open
sukus21 wants to merge 3 commits intoxem:sukus21from
sukus21:model-handling
Open

Save bytes in model handling code#43
sukus21 wants to merge 3 commits intoxem:sukus21from
sukus21:model-handling

Conversation

@sukus21
Copy link
Collaborator

@sukus21 sukus21 commented Feb 23, 2026

I found a couple of potential improvements in the model handling code used throughout the framework. Using the build scripts previously introduced, I was able to measure precisely what did and didn't help reduce the file size.

What has changed:

  • Declare some previously undeclared variables (and remove some unused variables)
  • W.smooth has had several byte-saves added
    • Input to the function is now a model, instead of a state object
    • The iterator logic has been reworked, saving bytes and a variable
    • The polygon "hash" (now built using Array.prototype.join) is reused from a variable
  • Model data has been moved to a variable, access now uses fewer bytes
  • Changed "compute only" functionality
    • Flag is now implicit, if model does not exist
    • In debug mode, trying to render a model that does not exist (and is not "camera", "light" or "group") will emit a warning
  • Moved buffer building logic to W.render
    • This was done since we already have the model in a variable in that scope, freeing up bytes

File size changes:

w.min.full.js: 7732 bytes (-830)
w.min.lite.js: 5642 bytes (-509)
w.min.full.zip: 2660 bytes (-92)
w.min.lite.zip: 2065 bytes (-64)

Despite adding more code in a few places, removal of the unused variables in `W.setState` end up saving space overall.

w.min.full.js: 8553 bytes (-29)
w.min.lite.js: 6132 bytes (-19)
w.min.full.zip: 2745 bytes (-7)
w.min.lite.zip: 2119 bytes (-10)
Several things have been optimized here:
* Input to the function is now a model, instead of a state object
* The iterator logic has been reworked, saving bytes and a variable
* The polygon "hash" has been saved to a variable, saving bytes
  * Additionally, it is now created using Array.prototype.join, saving even more bytes

compared to previous commit:
w.min.full.js: 8237 bytes (-316)
w.min.lite.js: 6132 bytes (±0)
w.min.full.zip: 2709 bytes (-36)
w.min.lite.zip: 2119 bytes (±0)
* Model has been moved to a variable, access now uses fewer bytes
* Changed "compute only" functionality
  * Flag is now implicit, if model does not exist
  * In debug mode, trying to render a model that does not exist (and is not "camera", "light" or "group") will emit a warning
* Moved buffer building logic to `W.render`
  * This was done since we already have the model in a variable in that scope, freeing up bytes

compared to previous commit:
w.min.full.js: 7732 bytes (-505)
w.min.lite.js: 5642 bytes (-490)
w.min.full.zip: 2660 bytes (-49)
w.min.lite.zip: 2065 bytes (-54)
@sukus21 sukus21 changed the title Save 60+ bytes in model handling code Save bytes in model handling code Feb 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant