Skip to content

refactor: use # for private methods to reduce the minified file size#357

Open
Master-Hash wants to merge 2 commits intodimforge:masterfrom
Master-Hash:private-opt
Open

refactor: use # for private methods to reduce the minified file size#357
Master-Hash wants to merge 2 commits intodimforge:masterfrom
Master-Hash:private-opt

Conversation

@Master-Hash
Copy link
Copy Markdown

@Master-Hash Master-Hash commented Oct 23, 2025

This PR reduces the bundle size using # for the private properties instead of the private keyword when the code is minified.

The results of esbuild ./rapier.js --bundle --minify --target=esnext --format=esm --outfile=out.js:

-a---          2025/10/23    19:36         112241 old.js
-a---          2025/10/23    20:12         111075 new.js

which is about 1.04% smaller. If you can find more private methods/property, It can be even smaller.

The principle is explained here.

The PR is tested on my own app.

@krutoo
Copy link
Copy Markdown

krutoo commented Apr 1, 2026

But you also replaced protected members - this is wrong because now you can use it in child classes

@Master-Hash
Copy link
Copy Markdown
Author

But you also replaced protected members - this is wrong because now you can use it in child classes

It causes no runtime error. I'm not sure whether it should be private or protected: if you are sure, I'll revert it.

@krutoo
Copy link
Copy Markdown

krutoo commented Apr 1, 2026

It causes no runtime error. I'm not sure whether it should be private or protected: if you are sure, I'll revert it.

To be honest, I'm not sure either (the library author decides), but protected and private access modifers in TypeScript is needed not for runtime but for compile time to declare bounds of fields access when working with a class and its instances

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.

2 participants