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

Better handling of precomputed tables #7

Closed
fjarri opened this issue Dec 31, 2022 · 1 comment
Closed

Better handling of precomputed tables #7

fjarri opened this issue Dec 31, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@fjarri
Copy link
Member

fjarri commented Dec 31, 2022

We have some precomputed reciprocals that we use in sieving (see precomputed.rs). We currently use lazy_static to handle lazy evaluation ofthose.

lazy_static has some side effects (spin_no_std feature is enabled for all other instances of lazy_static in the dependency tree - see rust-lang-nursery/lazy-static.rs#204).

once_cell is an alternative to it. It will be eventually included in the language (rust-lang/rust#74465). There is a problem though: in order to have no_std, once_cell needs the critical-section feature enabled; critical-section crate is brittle (it requires the user of the final application to be aware of it and follow some rules; see https://docs.rs/critical-section/latest/critical_section/#usage-in-libraries).

Another variant is, of course, creating the Reciprocal objects directly during compilation. It doesn't seem to be very slow, but will take about 400kb.

Ideally, whatever we choose, it should be gated by a feature. Need to also test how slow it actually is (especially relatively to the primality checks) to compute the reciprocals on the fly.

@fjarri fjarri added the enhancement New feature or request label Dec 31, 2022
@fjarri
Copy link
Member Author

fjarri commented Dec 31, 2022

Removed reciprocal precomputation in 09a8f12 - the performance difference is negligible compared to actual primality checks, so all the brittle lazy evaluation libraries are simply not worth the trouble. This can be reverted when once_cell is a part of Rust proper.

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