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

Use BitMaps to validate multiple types #78

Merged

Conversation

macisamuele
Copy link
Contributor

@macisamuele macisamuele commented May 22, 2020

The goal of this PR is to improve memory utilisation of MultipleTypesValidator as well as improving validation performance.

The validation performance is achieved by:

  • replacing iteration over a Vec instance (data are into the heap) with bit operations
  • ensuring that errors are as small as possible

Performance improvements have been measured by running the following

rm -rf target/criterion
git co -f 4cf7d8d
cargo bench "type_multiple"
git co -f 9437e9d
sleep 60  # To allow cooling down the laptop
cargo bench "type_multiple"

The raw output is available here
Summary:

  • ~21% improvement in compile time
  • at least 12% improvement in validation time (it goes up to 34% as well)

NOTE: I've run a subset of benchmarks only selecting the relevant to multiple types

Bitmaps allow lower memory footprint and faster checks as we remove vec iterations during validation
@Stranger6667
Copy link
Owner

Thank you Samuele!
It is an ingenious trick and I like it a lot :) Great!

What do you think if we can apply it somewhere else as well?

@macisamuele
Copy link
Contributor Author

I've noticed this "easy win" while working on maci-split-validators.
The branch is far from been really presentable (meant to provide a possible solution for #63)

@Stranger6667 Stranger6667 merged commit 52b033c into Stranger6667:master May 22, 2020
@macisamuele macisamuele deleted the maci-primitve-types-bit-map branch May 22, 2020 20:03
@Stranger6667
Copy link
Owner

Cool! Looking forward to seeing a pull request :)

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