protagonist icon indicating copy to clipboard operation
protagonist copied to clipboard

Can we slim down "release" builds?

Open kylef opened this issue 6 years ago • 7 comments

When you npm install protagonist into a project, it takes up around 100MB, over 90MB of that is built artefacts which are not needed by Protagonist at runtime, all that is really needed from build at runtime is build/release/protagonist.node.

Screenshot 2019-07-01 at 13 38 17

kylef avatar Jul 01 '19 12:07 kylef

Posting as a question, not sure how feasible it is. Perhaps we can hook into GYP to delete some of the build state for release builds.

kylef avatar Jul 01 '19 12:07 kylef

In theory, something like the following should contain everything for the runtime: Screenshot 2019-07-01 at 13 51 28

We do need to consider that some of the LICENSE files for vendored dependencies are not there and how to ensure they are always present.

kylef avatar Jul 01 '19 12:07 kylef

Looking at the GYP documentation, doesn't appear to be any hooks or way we can execute code, and even if we could it would be tricky to make it platforn independent. I think an NPM hook for postinstall may be the best option, we can produce a Node file which contains instructions to delete the artefacts for Release builds (we can omit these for debug).

kylef avatar Jul 17 '19 09:07 kylef

I thought we need *.a files because protagonist.node is dynamically linked. Did you get it working after deleting those things after installing protagonist as a module?

pksunkara avatar Jul 17 '19 11:07 pksunkara

Yes, it works. .a is a static library, it is used to build protagonist.node. protagonist.node does not dynamically link to anything other than libc++ and system libraries once built:

$ otool -L build/Release/protagonist.node
build/Release/protagonist.node:
	/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 400.9.4)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.250.1)

kylef avatar Jul 17 '19 11:07 kylef

Any progress on this? We'd love to take advantage of this slimmed down release.

gap777 avatar Nov 07 '19 15:11 gap777

@gap777 There hasn't been, I am not entirely sure if it is possible from Protagonist alone. I haven't had chance to fully look into it, it might be up for discussion upstream in Node JS (node-gyp specifically: https://github.com/nodejs/node-gyp) since this can apply to all the C++ add-ons for Node.

If you want a slimmed down build, you can take a look at drafter.js, it's a pure JavaScript version of Protagonist (https://github.com/apiaryio/drafter.js/).

kylef avatar Nov 25 '19 15:11 kylef