-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Start moving third party libraries to use npm #9706
Conversation
Remove `sprintf` third party library
Rather than submit libraries to Source/ThirdParty, which always end up being modified for our build system and quickly go out of date, this change starts to use libraries via npm instead. Currently Autolinker, earcut, when, tween.js, rbush, kdbush, quickselect, and topojson are ported. The main hurdle that prevented us from doing this sooner was the fact that Cesium has a long history of not requiring a build step after every code change and has a goal of writing valid JS code, unlike many libraries today that mandate a bundler to turn invalid JS code into valid code. Rather than mandate a bundler during development, this initial step adds a "buildThirdyParty" function to the current "build" step. This function runs third party libraries (defined in the ThirdParty/npm/ folder) through RollUp and creates an equivalent file in `Source/ThirdPartyNpm`. The change to end users will be non-existent, especially since the combined Cesium.js will still re-export any third party modules as part of the private API just like it used to. This doesn't prevent code duplication for users using some of the same third party libraries as Cesium. This is just an improvement as to how depend on third party libraries internally. I think Cesium's days of being "bundler free" are probably limited long term, performance is the main hurdle and newer tools like esbuild may make that no longer a problem. But that's outside the scope of this initial goal.
Start of replacing submitted third party libraries with npm modules
Use npm for third party libraries
zip.js with npm
Move Gltf-Pipeline to Source/Scene
…into npm-third-party-staging
Move FXAA3_11 shader into Source/Shaders
Thanks for the pull request @ebogo1!
Reviewers, don't forget to make sure that:
|
CHANGES.md
Outdated
@@ -6,6 +6,7 @@ | |||
|
|||
- Added `ImageryLayerCollection.pickImageryLayers` which determines the imagery layers that are intersected by a pick ray. [#9651](https://github.com/CesiumGS/cesium/pull/9651) | |||
- Added a `polylinePositions` getter to `Cesium3DTileFeature` that gets the decoded positions of a polyline vector feature. [#9684](https://github.com/CesiumGS/cesium/pull/9684) | |||
- Started moving over third party libraries to use npm modules. | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the right place to mention the change? I think there should be a note of this somewhere in CHANGES.md.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has zero user facing implications at this time, while we are moving to npm, there are still build time dependencies, not runtime dependencies (i.e. users who use Cesium don't actually have a direct dependencies on these libraries via npm)
Move ThirdPartyNpm files into ThirdParty
@@ -0,0 +1,2 @@ | |||
import pako from 'pako'; | |||
export { pako as default }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If all we use is pako-inflate, would it be better to only include inflate here? Then make sure roll-up treeshakes and it should create a smaller file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
treeshaking may not work, but pako also includes an inflate only dist.. looks like we can save over a hundred KB by using that instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be as simple as going back to inflate only like:
import pako_inflate from 'pako/lib/inflate.js';
export { pako_inflate as default };
and then update the calling code to just call pako_inflate
instead of pako.inflate
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I'm wrong.. you literally don't need to change the calling code.. just do
import pako from 'pako/lib/inflate.js';
export { pako as default };
and you end up with a pako
object that only has inflate related stuff.
@ebogo1 it would be better to look at the size of the actual combined Cesium.js files and the files in workers.. the size of the zips, while indicative of size differences, don't really tell us what users are pulling down to use Cesium over the network. |
Looks like we added ~512KB to the size to the combined/unminified Cesium.js and then a similar amount to the Workers, this is most likely caused by including way more of some third party libraries than we used to (like pako). It's probably easy to fix,but do we have any idea as to which libraries are causing the issue? |
I updated gltf-pipeline in dc2e925. gltf-pipeline now uses prettier, though it uses a different version of prettier than CesiumJS so I couldn't remove it from @ebogo1 I tagged you to review CesiumGS/gltf-pipeline#600 which has some fixes for generating these files for CesiumJS. |
After importing less from |
I looked into the file size discrepancy more and don't think there's an easy solution:
@mramato I could be wrong but is the only alternative here to try a different zip npm library? As of the last commit:
|
All in all, this is okay with me as an incremental step. But it's made it more clear than ever that we need to bite the bullet and migrate to "live" compilation where Cesium dev doesn't function without tooling building valid JS in the background. The industry and moved on and we aren't doing our service by trying to hold on to the old ways. In particular I diffed main and this branch zip output and went through the combined Cesium.js diff by diff and nothing major jumped out. Everything appears to work locally as well. I do have two questions:
Both can be handled in follow-up PRs. @lilleyse if you are okay with this feel free to merge. |
This is a chunk of progress towards #9473.
Comparing the generated .zip files with the one in main after #9705 gets merged:
Cesium.js
is 3.9 MB in this branch vs 3.7 MB in main (uncompressed)Comparing the .tgz with main:
decodeGoogleEarthEnterprisePacket
is about 1.5x as big in this branch; probably because we're importing more than we need frompako
..