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

Remove atomic64 feature and use crossbeam::atomic::AtomicCell<u64> for all targets? #41

Open
tatsuya6502 opened this issue Sep 14, 2021 · 3 comments
Labels
enhancement New feature or request

Comments

@tatsuya6502
Copy link
Member

In order to support target platforms without AtomicU64, we added a Cargo feature called atomic64 to Moka v0.5.3 and put it into the default feature list (#38, #39).

  • If the feature is enabled, Moka keeps the old behavior (by using AtomicU64 as timestamps of cache entries).
  • Otherwise, it uses RwLock<Instant> so that it will compile for such targets.

The feature also controls whether quanta crate is used or not by Moka, because quanta v0.9.2 or earlier do not compile for such targets.

We might want to replace above with crossbeam::atomic::AtomicCell<u64> because it provides a similar functionality to AtomicU64 (when it is supported by the target) and RwLock<u64> (when AtomicU64 is not supported).

https://docs.rs/crossbeam/0.8.1/crossbeam/atomic/struct.AtomicCell.html

Operations on AtomicCells use atomic instructions whenever possible, and synchronize using global locks otherwise.

It will be more convenient as it switches implementations without having a Cargo feature like atomic64. It combines auto-generated Rust source and the build script to achieve auto-switching.

Also, the next version of quanta will support these targets (metrics-rs/quanta#55), so once it is released, we can always enable quanta.

@tatsuya6502
Copy link
Member Author

Before switching to AtomicCell<T>, we need to check its implementation to see if it as efficient as our current implementation.

@tatsuya6502 tatsuya6502 added enhancement New feature or request blocked Blocked by something labels Sep 14, 2021
@tatsuya6502
Copy link
Member Author

Also, the next version of quanta will support these targets (metrics-rs/quanta#55), so once it is released, we can always enable quanta.

quanta v0.9.3 has been released and Moka v0.5.4 (next version) and newer will always enable quanta (#42).

@tatsuya6502 tatsuya6502 removed the blocked Blocked by something label Sep 16, 2021
@tatsuya6502
Copy link
Member Author

Started to use AtomicCell<u64> for wight based eviction: 4404e6f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant