Skip to content
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

stick to a single compiler: babel vs tsc #77303

Closed
mshustov opened this issue Sep 14, 2020 · 6 comments
Closed

stick to a single compiler: babel vs tsc #77303

mshustov opened this issue Sep 14, 2020 · 6 comments
Labels
discuss high hanging fruit impact:low Addressing this issue will have a low level of impact on the quality/strength of our product. loe:small Small Level of Effort Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc Team:Operations Team label for Operations Team

Comments

@mshustov
Copy link
Contributor

mshustov commented Sep 14, 2020

In #77298 some compilation perf problems have been reported. I'd like to discuss options we have to decrease the compilation pipeline complexity. The main question is whether we need to run 2 different compilers: babel for code generation, tsc for type check and type declaration output, if most of our code is written in TS.
Pros of babel:

  • rich plugin system. we can write a custom plugin and use 3rd party plugins. Our babel plugin deps:
    • babel-plugin-styled-components
    • babel-plugin-transform-imports
    • babel-plugin-filter-imports
    • babel-plugin-transform-define
    • babel-plugin-istanbul
  • auto-polyfilling with @babel/env

Benefits of tsc:

  • type checks during compilation (right now we can see no type errors when yarn start, yarn test:jest --watch)
  • faster builds as we don't have to parse source code twice for *.ts files (parse TypeScript code to remove type annotations in the first pass, parse JS code in the second pass, generate source maps)
  • faster re-builds (in theory) with incremental mode
  • ability to use TS specific features not supported by Babel https://devblogs.microsoft.com/typescript/typescript-and-babel-7/#caveats

Rebuilding the whole build-toolchain is a significant effort, so this issue is rather an attempt to discuss our long term vision on the ideal state of the matter.

For me, it makes sense to investigate tsc usage on the server-side to understand whether we gain a lot switch to it.

@mshustov mshustov added discuss Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc Team:Operations Team label for Operations Team labels Sep 14, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-platform (Team:Platform)

@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-operations (Team:Operations)

@tylersmalley
Copy link
Contributor

The current plan for #69706 is to use tsc, as among other things, having the types outputted allows for optimizations to determine if downstream projects need to be rebuilt.

@kobelb
Copy link
Contributor

kobelb commented Sep 21, 2020

I was able to hack a distributable of Kibana to no longer utilize babel-register. Kibana was able to start-up and I was able to use basic functionality. It reduced the JS heap usage by approximately 200mb, so there are likely some benefits that we'd get from removing babel-register in production and locally. There are also some complications here, but it looks promising.

@mshustov
Copy link
Contributor Author

@kobelb a separate issue created #78168

We discuss the pros and cons on our today's DX meeting and decided on using tsc as a default compiler by default. The main pros: we want to piggyback on TS incremental builds, plus we are going to run tsc to generate type definitions anyway.

@tylersmalley tylersmalley added 1 and removed 1 labels Oct 11, 2021
@exalate-issue-sync exalate-issue-sync bot added impact:low Addressing this issue will have a low level of impact on the quality/strength of our product. loe:small Small Level of Effort labels Oct 12, 2021
@tylersmalley
Copy link
Contributor

With our discovery and plan to address #107648, we have found that we need to use both Babel and tsc, but use tsc sparingly and only when generating types and Babel to quickly transpile code.

@mshustov, can we close this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discuss high hanging fruit impact:low Addressing this issue will have a low level of impact on the quality/strength of our product. loe:small Small Level of Effort Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc Team:Operations Team label for Operations Team
Projects
None yet
Development

No branches or pull requests

4 participants