Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Speed up AST dump by only including API headers #759

Merged
merged 1 commit into from
Jun 16, 2023
Merged

Conversation

fhanau
Copy link
Collaborator

@fhanau fhanau commented Jun 11, 2023

As part of a wider effort to improve CI compile times, only compile the api headers when generating the clang ast dump.
The reduced AST (which needs to be generated, gzip-compressed and parsed by param_extractor) is significantly smaller as api.ast.json.gz goes from 167MB to 119MB, further reducing CI disk usage. This improves the local runtime of generating api.ast.json.gz and subsequently param-names.json from 27s to 20s. As this is a potential bottleneck when compiling all targets, it should help improve the critical path compile time.
I have verified that the generated types (i.e. //types:types) are identical.

Note: upstream does not use either of the files affected, so no upstream PR is needed.

@fhanau fhanau requested review from mikea, ohodson and penalosa June 11, 2023 19:47
#include <workerd/io/compatibility-date.h>
#include <workerd/jsg/rtti.h>

#if !API_ENCODER_HDRS_ONLY
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With such a large #if..#endif block, we could consider splitting this file into two files, something like "tools/workerd-apis.h" and "api-encoder.c++".

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm kind of torn on this but have a slight preference for keeping it as-is. Having a separate file for the headers would make the AST generation input more clean, but it would also mean having a file just containing 19 include directives that is of little use elsewhere (it could be used to include API headers elsewhere, but in my include cleanup patches I have been trying to avoid including the entire API when this is not strictly required; the size of the includes tends to negatively affect compile times). Overall, it makes sense to me referring to the api encoder source as it is also used for type generation and necessarily includes the entire API.

@ohodson
Copy link
Contributor

ohodson commented Jun 12, 2023

Nice improvement!

It would be nice-to-have the comment that goes with the PR in the commit message too.

Copy link
Contributor

@ohodson ohodson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but probably best to get input from Somhairle as the original author.

Only compile the api headers when generating the clang ast dump.
This reduces the size of the generated AST by about a quarter and allows us to
reduce the time spent on AST generation, AST parsing and parameter extraction.
This is particularly useful when compiling all targets such as on the CI build,
where AST generation, parameter extraction and the subsequent type generation
represent a bottleneck, so reducing the AST size should help improve the
critical path compile time.
The generated types are unaffected by this change.
@fhanau fhanau force-pushed the felix/ast-dump-opt branch from 5ee31a7 to e04d8d6 Compare June 13, 2023 14:26
@fhanau
Copy link
Collaborator Author

fhanau commented Jun 13, 2023

Nice improvement!

It would be nice-to-have the comment that goes with the PR in the commit message too.

Done!

@fhanau
Copy link
Collaborator Author

fhanau commented Jun 13, 2023

LGTM, but probably best to get input from Somhairle as the original author.

I agree – any suggestions @penalosa?

@fhanau fhanau merged commit 26af1d2 into main Jun 16, 2023
@fhanau fhanau deleted the felix/ast-dump-opt branch June 16, 2023 14:43
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants