-
Notifications
You must be signed in to change notification settings - Fork 28
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
feat: use composite builds to speed up compilation #692
base: develop
Are you sure you want to change the base?
Conversation
I'll review tomorrow, but I pulled in Tom as well for a review, since I would not rely on my own review for this stuff. |
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.
I like the improvements! I left few comments/questions, but as I said, I would like someone else's opinion on the changes.
package.json
Outdated
"check": "tsc -p tsconfig.json --noEmit", | ||
"build": "yarn workspaces foreach -p -t --exclude '{root-workspace}' run build", | ||
"check": "tsc -b tsconfig.json", | ||
"build": "yarn clean && yarn workspaces foreach -pt --exclude 'root-workspace' run build", |
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 we run yarn clean
before a build, we lose the incremental compilation benefit you mention in the PR description, I guess. So we should probably not clean by 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.
This is by design; yarn build
is only meant to be run for production builds essentially (it's also the command run in CI). Running a clean beforehand makes sure we don't get any weird artefacts. For standard builds and rebuilds in development you can simply use build:dev
.
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.
As mentioned below, we should then somehow advertise that build:dev
is the to-go command then.
"check": "tsc -b tsconfig.json", | ||
"build": "yarn clean && yarn workspaces foreach -pt --exclude 'root-workspace' run build", | ||
"build:dev": "yarn workspaces foreach -pt --exclude 'root-workspace' run build:cjs", | ||
"build:watch": "yarn build:dev && tsc -b tsconfig.json --watch", |
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.
What's the benefit of this?
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.
It complains as soon as you break something and is more efficient as running yarn check
or yarn build:dev
repeatedly. Also I would have to double check but potentially you need to have it running if you are using jest in watch mode.
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.
just checked, you would want to have this running as well if jest is running in watch mode to make sure packages are being rebuild on changes. Otherwise imports from another package may use out of date versions.
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.
So this is supposed to be run before and during tests? And yarn build:dev
alone then when?
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.
Again, this is for watch mode. As in, you keep jest running and it re-executes tests whenever you change a file. So far we didn't have a solution for that. You can also just run yarn build:dev && yarn test
whenever you want to test of course. It's a question of preference.
As for the naming, I was considering making yarn build:dev
the new yarn build
and introducing a yarn build:production
instead for release builds. Do you think that's better? I decided to go the other way because there is no harm in running the production build in a development scenario (it's just slower) but it would be bad to release a development build because the esm files are missing.
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 makes sense. Rather use the build for development and something else for production.
package.json
Outdated
"build": "yarn workspaces foreach -p -t --exclude '{root-workspace}' run build", | ||
"check": "tsc -b tsconfig.json", | ||
"build": "yarn clean && yarn workspaces foreach -pt --exclude 'root-workspace' run build", | ||
"build:dev": "yarn workspaces foreach -pt --exclude 'root-workspace' run build:cjs", |
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.
I guess this is to be used before unit/integration tests? Can we mention it somewhere? Otherwise I am 99% sure people will still be running yarn build
.
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.
True, I haven't updated READMEs and such. Could also add comments above the respective scripts
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.
Okay so we don't have a section on development in the README and we can't add comments to the package.json, where do you think we should put that info?
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.
I guess the README then? I don't see any other place where this could go, personally. Maybe @arty-name has some prior experience for this?
Agree, would be a great idea to get @arty-name's review on this as well. |
I barely have experience with managing monorepos, but I do often see how they invite piling on workarounds and complexity. I am still of the opinion that the SDK should not be a monorepo, and everything will become much simpler and way, way quicker. Composite builds? Never heard of them, frankly. |
@arty-name just out of curiosity, how would a non-monorepo SDK look like? Still all packages in the same repo, I guess? And then each with its own |
Why would they even need their own package.json? An example: move /packages/core/src/* to /src/core/. That’s it! |
An example of increasing complexity: now you need to add extra knowledge to the readme, and there are multiple places that "must be in sync with @KILTprotocol imports in package.json". And then you might be adding in the readme on how to diagnose and solve weird errors that happen when you forget to manually update that thing that must be in sync. |
I see. So it would become one big package instead of multiple smaller ones, right? |
Yes, making something a monorepo is splitting a big package into multiple smaller ones, while removing a monorepo is joining multiple smaller packages into a single bigger one. I have been reporting for quite some time that the SDK’s experiment with a monorepo has failed, in my opinion, and should be reverted. |
I don't really see the end-the-monorepo discussion as related to this change. I'm not saying we shouldn't do it, but it's a different thing. It would completely change the surface of the sdk, while this is just an optimisation of internals.
That brings down rebuild times from a whopping 2-3 minutes to less than 10 seconds. This is vital for me to be able to work efficiently. |
According to the PR title, this change is to speed up things, and the "no monorepo" achieves the same goal of 10 seconds. At least I had that a couple of months ago in a quick test.
As far as I can remember, using sub-packages was never recommended, and the surface of |
That's great, but we simply do not know what would break if we discontinue 10 packages we have published to npm, and 'not having recommended to use them' does not really change anything about that. This is going to take a bit of evaluation and deliberation and is not going to happen tomorrow. |
As I have said in my first comment on this PR #692 (comment) I cannot really contribute here, sorry. I guess the PR achieves its goals 🤷 |
fixes KILTProtocol/ticket#2331
In this PR I introduce several optimisations to bring down typescript compile times.
references
in the tsconfig files of each package that mirrors their dependencies on other packages in the monorepo (as indicated by theirpackage.json
).build:dev
command that is sufficient for testing and development. It only builds cjs and type files.How to test:
Checklist: