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

Push makeExecutable down into AbstractFileWriteAction subclasses #22609

Closed
wants to merge 2 commits into from

Conversation

fmeum
Copy link
Collaborator

@fmeum fmeum commented Jun 1, 2024

Getting rid of the single boolean field on AbstractFileWriteAction reduces padding on each subclass instance and in particular frees up a 4-byte field on CppModuleMapAction.

Also use a lambda to define newDeterministicWriter if possible for improved readability.

This prepares for future changes that will add fields to CppModuleMapAction to support path mapping.

Work towards #6526

@fmeum fmeum requested review from a team and lberki as code owners June 1, 2024 21:43
@fmeum fmeum requested review from gregestren and removed request for a team June 1, 2024 21:43
@github-actions github-actions bot added team-Configurability platforms, toolchains, cquery, select(), config transitions team-Rules-CPP Issues for C++ rules team-Rules-Python Native rules for Python awaiting-review PR is awaiting review from an assigned reviewer labels Jun 1, 2024
public boolean makeExecutable() {
// In theory, module maps should not be executable but, in practice, we don't care. As
// 'executable' is the default (see ActionOutputMetadataStore.setPathReadOnlyAndExecutable()),
// we want to avoid the extra file operation of making this file non-executable.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@justinhorvitz I wonder whether this comment is still correct in light of

It looks like having makeExecutable() return true always results in that file operation, so not sure whether possibly saving another one elsewhere gains anything. I could drop this if you think it's not needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

I looked up the history of this comment and found more context. It is referring to a google internal implementation of FileWriteStrategy which only calls setExecutable(false) because our remote execution strategy already makes files executable by default. You can add this clarification to the comment if you wish.

Copy link
Collaborator Author

@fmeum fmeum Jun 3, 2024

Choose a reason for hiding this comment

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

I see. Could it make sense to have makeExecutable be ternary (with a "don't care" state) to make this more efficient for Bazel?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's a good idea but I don't know how to measure the value. I also wonder whether we really need to make anything explicitly not executable, or whether false can be used for "don't care."

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 also don't know how to assess whether this is even worth it. Since ctx.actions.write exposes the executable bit in public API, we would probably need ternary state somewhere. I will consider looking into this as a follow-up at some point.

@fmeum fmeum marked this pull request as draft June 1, 2024 21:50
@fmeum fmeum force-pushed the abstract-file-write branch 4 times, most recently from f7dfb8f to b32243a Compare June 2, 2024 09:36
Getting rid of the single boolean field on `AbstractFileWriteAction` saves 8 bytes on each subclass instance due to padding.

Also use a lambda to define `newDeterministicWriter` if possible for improved readability.

This prepares for future changes that will add fields to `CppModuleMapAction` to support path mapping.

Work towards bazelbuild#6526
@fmeum fmeum marked this pull request as ready for review June 2, 2024 09:38
@fmeum fmeum requested a review from justinhorvitz June 2, 2024 09:38
public boolean makeExecutable() {
// In theory, module maps should not be executable but, in practice, we don't care. As
// 'executable' is the default (see ActionOutputMetadataStore.setPathReadOnlyAndExecutable()),
// we want to avoid the extra file operation of making this file non-executable.
Copy link
Contributor

Choose a reason for hiding this comment

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

I looked up the history of this comment and found more context. It is referring to a google internal implementation of FileWriteStrategy which only calls setExecutable(false) because our remote execution strategy already makes files executable by default. You can add this clarification to the comment if you wish.

@fmeum
Copy link
Collaborator Author

fmeum commented Jun 14, 2024

@justinhorvitz Friendly ping

@github-actions github-actions bot removed the awaiting-review PR is awaiting review from an assigned reviewer label Jun 14, 2024
@fmeum
Copy link
Collaborator Author

fmeum commented Jun 14, 2024

@bazel-io fork 7.3.0

@fmeum fmeum deleted the abstract-file-write branch June 14, 2024 15:07
bazel-io pushed a commit to bazel-io/bazel that referenced this pull request Jun 14, 2024
Getting rid of the single boolean field on `AbstractFileWriteAction` reduces padding on each subclass instance and in particular frees up a 4-byte field on `CppModuleMapAction`.

Also use a lambda to define `newDeterministicWriter` if possible for improved readability.

This prepares for future changes that will add fields to `CppModuleMapAction` to support path mapping.

Work towards bazelbuild#6526

Closes bazelbuild#22609.

PiperOrigin-RevId: 643340715
Change-Id: Id3af26049098e6dfa731f0e7a1be6709bea0d9f2
fmeum added a commit to fmeum/bazel that referenced this pull request Jun 21, 2024
Getting rid of the single boolean field on `AbstractFileWriteAction` reduces padding on each subclass instance and in particular frees up a 4-byte field on `CppModuleMapAction`.

Also use a lambda to define `newDeterministicWriter` if possible for improved readability.

This prepares for future changes that will add fields to `CppModuleMapAction` to support path mapping.

Work towards bazelbuild#6526

Closes bazelbuild#22609.

PiperOrigin-RevId: 643340715
Change-Id: Id3af26049098e6dfa731f0e7a1be6709bea0d9f2
github-merge-queue bot pushed a commit that referenced this pull request Jun 21, 2024
…classes (#22845)

Getting rid of the single boolean field on `AbstractFileWriteAction`
reduces padding on each subclass instance and in particular frees up a
4-byte field on `CppModuleMapAction`.

Also use a lambda to define `newDeterministicWriter` if possible for
improved readability.

This prepares for future changes that will add fields to
`CppModuleMapAction` to support path mapping.

Work towards #6526

Closes #22609.

PiperOrigin-RevId: 643340715
Change-Id: Id3af26049098e6dfa731f0e7a1be6709bea0d9f2

Closes #22749 
Closes #22750
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team-Configurability platforms, toolchains, cquery, select(), config transitions team-Rules-CPP Issues for C++ rules team-Rules-Python Native rules for Python
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants