-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
-- size, ++ speed #8824
-- size, ++ speed #8824
Conversation
Related: #8822 |
The package.json in build should be deprecated and replaced with the one in the root. It is no longer useful to have it in there. |
Ah! What is a smooth way to deprecate it? Is |
@gero3 If so, can we just invoke the build from the root directory, maybe? |
I like the idea of the constifier but not the implementation right now. Mostly because it requires us to keep track of constants in 2 places now.
Just delete the file. It is just a relic now. Nobody should be using it anyway. It isn't kept up to date anyways.
I actually would add the following actually. That way it is similar to the python version.
|
Yes, it also runs on WIndows. The build script is made to run specifically from the directory, similar to the python script. |
@tschw |
Because it doesn't. See |
Also, these names are global variables, not constants. So they should follow the conventions for variables not constants. We could put some deprecation code into @tschw wrote:
I guess it might be possible to automate it even further, using this tool only only for hard-wiring the WebGL constants, extracting the |
Using Eval the concatenated source code could get you the the THREE object which can be used in the findConstants object. |
Would it be a (better) option to just |
It does. But you can't require a string without writing it to the disk somewhere. |
Ah cool!
Right - it's only in memory with the JS build... Isn't Maybe constant extraction should just be a separate invocation that performs a debug build as a prerequisite? @mrdoob Yet another option (that would allow them to remain uppercased) would be to move them onto the classes, e.g. |
uglify is very slow compared to the extraction process normally. It shouldn't take a second to get all of the constants. |
Why don't we just adopt JavaScript symbols which are designed for this? https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Symbol Constantly like this do not really impact ThreeJS's size at all because they get reduced by gzip. This seems like a special case hard to maintain gzip step that isn't necessary. I would like to see the differences in resulting gzip size before and after this PR. Is it significantly better? I've done my own experiments before with changing THREE to T and Vector3 to V3 and it made almost no difference in the resulting gzip file because well compression. I do not understand the point of this PR. Also this PR changes the static variable naming convention from first uppercase letter to lowercase for a number of constants. I am okay with changing convention but as its own PR. |
@gero3 wrote:
I completely agree. :) |
Just kill it, it doesn't work well and I doubt many are using it. |
...won't make the properties constant. Only the data. Also, they are unsupported by most browsers.
There is no gzip step.
Just see above. It's 2KB gzipped and that equates to a lot of code... |
Most webservers serve *.js files (and other text files) as gzipped (or soon brotli) automatically, at least in professional contexts. https://en.wikipedia.org/wiki/HTTP_compression Many webservers, like nginx, and do this transparently and cache the gzipped intermediates automatically: http://nginx.org/en/docs/http/ngx_http_gzip_module.html |
@bhouston |
Those occur much more frequently, therefore compress to almost nothing anyway. |
2K, that is sort of what I saw as well, that is 2% saving, which isn't much. This to me isn't a major issue. I am not sure that is sufficient to obfuscate the source files like this and duplicate the constants in two places which increases the maintenance complexity of Three.js. I really do not like violating DRY just to save 2K: https://en.wikipedia.org/wiki/Don%27t_repeat_yourself for just a 2K saving. There are higher priority issues with ThreeJs in my opinion. |
I slightly oppose this for now because of the DRY violation. But if that was addressed, I wouldn't have much of an opinion on this PR either way, the savings are minimal, but the build step can easily be turned off is needed, so it sort of nets out to even. |
Please read the full thread before opposing because there is none. Constant extraction was automated right from the start and I'm currently automating it further. It will be completely transparent. |
@bhouston |
2K gzipped actually equates to a lot of code! |
RE the see: https://github.com/abelnation/three.js/blob/improve-npm-build/utils/build/build.js#L8 |
If other tools use the constified version and try to use THREE.XXXXXX what happens? Do they have to run this script on all of their code too? Do the examples work with this new version without changes? |
It's also safe to use code like THREE.XXXX = 111; and the token will not be replaced in this case. |
I wouldn't even dare to make this a PR if they didn't :) |
Would it be possible to split this PR in two? I would like to tackle the |
- Without it 'npm install' issues a warning message.
- Replaces THREE and WebGL symbolic constants with numerals. - Reduces the build size by (currently) 8KB / 2KB gzipped. - Improves the performance of the renderer's JS code.
d8d5d06
to
219b579
Compare
Sure. Thought at first this one broke, but then I looked at the build and everything was looking fine. Turns out I was in fact just testing |
Haha! |
@mrdoob |
Actually, I was thinking we could make these counters internal. Like... THREE.Texture = ( function () {
var id = 0;
return function () {
Object.defineProperty( this, 'id', { value: id ++ } );
};
} )(); This should work fine with Also, I wonder if people relies on |
How about
The latter would keep it exposed and allow deprecation of the old name via Three.Legacy, but maybe it's exotic enough to just solve it by documenting it for the next release on the Migration page? |
/ping @mrdoob |
I like the idea, but the Rather than having to notify the user that these variables have changed name, I think I would like to remove them (using the approach in #8824 (comment)) and solve the Then the PR/Feature should be ready to go. |
Hi I believe this is the best thread to be commenting on. How is this coming along to reduce the filesize ? Is there a way to remove all the shaders not in use at all ? |
@danrossi More recently three.js has moved to ES6 modules and Rollup for its build (#9310). This means that for the particular case of pruning parts of three.js that aren't needed for your particular project, you can use tree-shaking in build systems like Rollup or Webpack. Here is an example of how to set that up: https://stackoverflow.com/questions/41538767/how-do-i-tree-shake-three-js-using-webpack-or-rollup As far as efforts to reduce the "default" size of threejs, I don't current status of this PR. |
Ok not a problem I might have to make another ticket. for my purpose the bundle has to stay global and so not packaged in. Yes I use such imports but it's global. I have a special build of three which only exports the required files. I can reduce it down to 350kb or there abouts. However there is alot of things that are still included unnecessarily like all the shaders and their respective uniforms configs. The shaders need to be modular somehow. I don't need any of them apart for MeshBasicMaterial and create my own with a RawShaderMaterial. Not sure where to ask about that. |
I figured out a hack here to prevent including all the shader code. In the rollup build its trying to transform them I just provide an empty string.
|
This code has proven to be a problem for an external project I am working on. I think this importing causes more problems than good. It is expecting three installed via npm. I might have to convert them all back to global prefixes. I can't just tell that code to treat three as global. Even though I am bundling that three code beforehand. I am trying to include the module of that project into a custom three bundle and its trying to include duplicated files and increase the filesize. I think it has even included minified sources from somewhere. Without that project included and with the shaders now removed I have managed to trim it down to 260kb !
|
I am using import constants for a custom shader with morph target requires. So I have to include these back into the bundle. All other shaders can go for my needs. It still setups up a heap of helper properties in the ShaderLib. So extra code not needed.
|
Please refer to this discourse in regards to one way tree shaking problems. The import system is only designed to bundle three.js into an app. You can use the elegant import setup in a 3rd party module build and set three as global in the rollup config. But when trying to bundle that module back into a custom three bundle you can't. The import code is tree shaking duplicated three module code for no reason and increases the size about 3 times. I think it even includes minified code. For bundled my custom modules I have to hard code locations of the sources. I am using three github sources not npm. And don't even want it to look for npm three. Sorry I don't know where else to report this. https://discourse.threejs.org/t/tree-shaking-three-js/1349/17?u=danrossi |
👍 |
This PR adds a custom build step that replaces THREE & WebGL symbolic constants with numerals. It also contains some minor cleanup based on diagnostics from the JS build.
The build step is implemented both in Python and in JavaScript for both build variants. It has a debug mode that logs the replacements.