Skip to content

Vector Clock Feature Flag#187

Merged
sarsko merged 2 commits intoawslabs:mainfrom
dylanjwolff:vector-clock-feature
Jul 30, 2025
Merged

Vector Clock Feature Flag#187
sarsko merged 2 commits intoawslabs:mainfrom
dylanjwolff:vector-clock-feature

Conversation

@dylanjwolff
Copy link
Copy Markdown
Contributor

@dylanjwolff dylanjwolff commented Jul 28, 2025

This PR adds a feature flag for vector clocks to boost Shuttle's testing throughput when they are not needed.

This feature flag is disabled by default in production, but always enabled for tests because many tests leverage vector clocks for assertions to check correctness. In the micro-benchmarks for the Shuttle repository, this results in performance gains of 5-25%:

criterion.tar.gz

When disabled, the VectorClock struct is replaced by an empty struct for which all operations are i.e. a no-op.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@dylanjwolff dylanjwolff marked this pull request as draft July 28, 2025 22:57
Comment thread shuttle/src/runtime/task/clock.rs Outdated
Comment thread shuttle/src/runtime/task/clock.rs Outdated
/// vector clocks are not necessary
#[cfg(all(not(test), not(feature = "vector-clocks")))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct VectorClock;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

My suggestion is to remove this and cfg all usages of VectorClock

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

it would be nice to not need a dummy implementation, but the issue with doing this is that there are other structs that have VectorClock's (e.g.

last_acquire: VectorClock,
) so the blast radius of this change is quite large and would result in the codebase being littered with #[cfg...]'s.

the dummy implementation keeps this PR quite small and gives us probably 99% of the performance benefits

@dylanjwolff dylanjwolff force-pushed the vector-clock-feature branch from 0e71f72 to 0c12dcd Compare July 29, 2025 22:09
@dylanjwolff dylanjwolff marked this pull request as ready for review July 29, 2025 22:26
Comment thread shuttle/src/runtime/task/clock.rs Outdated
Comment thread shuttle/Cargo.toml
trybuild = "1.0"
pin-project = "1.1.3"
# The following line is necessary to ensure vector-clocks are used for integration tests
# To run performance tests without vector clocks using `cargo bench`, this line must be commented out
Copy link
Copy Markdown
Contributor

@sarsko sarsko Jul 29, 2025

Choose a reason for hiding this comment

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

It is possible to do benching without vector clocks by introducing a feature (eg. bench-no-vector-clocks) and then gating vector clocks on all(any(test, feature = "vector-clocks"), not(feature = "bench-no-vector-clocks")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yup, this would allow you to run the benchmarks without vector clocks by enabling the feature at the command line rather than commenting this line out, which I agree is better. I can add it, but I am getting worried that this setup is a little counter-intuitive (feature is disabled by default, but always enabled for tests and benchmarks unless you use this other feature flag).

I'm starting to think it might be better to enable vector clocks by default, add it as a "required feature" for tests, and add a gated compile error to prevent ever using cargo test without the feature. I think this is slightly more intuitive: if the feature is enabled its enabled everywhere and if it is disabled, it is disabled everywhere (but should result in compile errors for testing). For example:

f9d5ced

Sorry for the back and forth on this!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think default enabling vector clocks (or most features tbh) is a mistake:

  1. It is a "poweruser" feature with runtime performance costs.
  2. The default offerings should be sensible. This is not a sensible default (noone has ever used it).
  3. The standard recommendation will be "oh and yeah, disable this feature" which is just bad UX.
  4. Feature enablement is additive. Having it as a default makes accidental opt-in the standard, which is a pain for projects which span multiple packages.
  5. One should opt-in to the functionality one wants, not opt-out of the functionality one does not want.

@sarsko sarsko enabled auto-merge (squash) July 30, 2025 23:29
@sarsko sarsko merged commit db45432 into awslabs:main Jul 30, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants