GithubHelp home page GithubHelp logo

unbrice / bench_vtables Goto Github PK

View Code? Open in Web Editor NEW
3.0 3.0 0.0 42 KB

A playground to experiment with various representation of V-Tables for multiple Rust traits. I created it in the context of rust-lang #2035

License: Apache License 2.0

Rust 100.00%
rust vtable compiler benchmark

bench_vtables's Introduction

SieveTable: v-tables for sum traits

This repo is a playground to experiment with various representations of V-Tables for multiple Rust traits.

I this repo in the context of rust-lang #2035. I wrote a blog post presenting the issue as well as a proposed solution. This repo is mostly so that I could benchmark that propsal. It could be useful to benchmark other approaches.

To give an overview, it proposes a representation that:

  • Allows turning a sum trait to a subset of the sum (Box<A+…+B+…+C>Box<A+B+C>) without heap allocations.
  • Keeps pointers to a sum-trait type on a regular two words fat-pointer.
  • Performs better than the often discussed "extra fat" pointers, at least on my x86_64 machine according to my naive benchmarks.
  • Does not require full program optimisation (individual crates can remain compiled separately).
  • Offers multiple variants and tuning opportunities for varying architectures.

More details in the blog post. Bencmarking is an art I am far from mastering, contributions are welcome.

Bench results

src/fibonacci.rs implements an inefficient recursive Fibonacci based on virtual calls. benches/fibonacci.rs benches it for various number of traits.

On 2021-10-24, I ran on a 2019 Mac cargo criterion and observed the following:

Size 1 trait 2 traits 3 traits 4 traits 5 traits
VPtr 2 words 402ns - - - -
PackedSieve 2 words - 464 ns 488 ns 482 ns 495 ns
InlineSieve 3 words - 510 ns 510 ns 510 ns 510 ns
MultiVPtr
(Extra-fat pointers)
N+1 words - 472 ns 753 ns 764 ns 831 ns

Interpretation

  • PackedSieve performed as well as MultiVPtr for 2 traits, and better for all other trait numbers, while also being smaller.
  • InlineSieve has the advantage of stable performance, as it does not depend on the number of traits. Nevertheless, it is a bit larger and significantly more complex.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

bench_vtables's People

Contributors

dependabot[bot] avatar unbrice avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.