The Solana Foundation was a sponsor at Rust Conf this year, and provided me with a ticket. On the first day, I mainly attended talks I was interested in and took notes. On the second day, I attended a few talks but mainly was in the Solana booth.

I’m posting my somewhat edited notes here.

Using Rust and Battlesnake to never stop learningLink to this heading

Talk mainly focused on profiling and optimizations.

  • Battlesnake is a competitive snake game. Build snake logic to survive the longest.
  • Uses MiniMax for actual decisions - this was not discussed further
  • Basic overview of flamegraphs
  • Early on found cloning the game state was expensive
  • Instead of cloning, moved and reversed move to get back to previous state
  • Found a crate battlesnake_game_types
    • optimized for speed
    • size of board representation/state is const
    • changing data representation actualy made cloning faster than move & reverse move

Infrastructure for Rust: Supporting a Growing Language & CommunityLink to this heading

Rust has been growing rapidly, and the infrastructure needs to keep up.

Contributors:

  • CI
  • Crate - for perf/regression testing
  • Bots - several github bots for triaging issues
  • Cloud Compute Program - access to compute resources for compiler testing

Users:

  • Rust Releases
  • crates.io
  • docs.rs

Rust download traffic growing exponentially.

  • Use Content Delivery Networks (CDN): CloudFront, Fastly
    • Moving towards Fastly (50-50 split currently)
  • Doesn’t infinitly scale though
  • CI accounts for 50% of traffic
    • Cache in GitHub Actions - avoid reaching out to CI
    • Can’t determine which traffic comes from actions vs users though
  • Long term want distributed network of mirrors
    • I wonder if this could be some sort of thing on IPFS?
    • Blocked by lack of cryptographic signing
      • Crates & Releases need to be signed so they can’t be tampered with

Rust Language CI:

  • More complex with every additional supported platform
  • This makes it slow - nearly 2 days of billable hours
  • Have generally optimized for simplicity rather than efficiency/scalability
    • This may need to change

The Standard Library is special. Let’s Change thatLink to this heading

  • How is the standard library special?
    • uses nightly features… on stable
    • can bypass coherence rules
    • has a prelude
    • not included in cargo
      • no feature flags
      • no options for optimizations (speed), i.e. can’t optimize for size
      • no versioning or breaking changes
  • What has to be special?
    • Language items: currently 130
    • Some are necessary, others are not
    • Compiler intrinsics: currently 232 (101 just for atomics!)
      • many can be removed
    • std aware Cargo working group
      • -Zbuild-std on nightly
    • std relies on unspecified behavior
      • relies on size and layout of fat pointers. These are not specified.
      • relies on mem::uninitialized being undefined behavior
    • Negative implementations
      • opt out of auto traits
    • Specialization:
      • current impl is unsound
      • largely stagnated
      • used for optimizations; but not available in public API
    • Crate preludes:
      • auto import of common items
      • Why can only std do this?
    • Stability attributes:
      • stable or not
      • unstable items are opt-in, w/ feature-gate

Extending Rust’s Effect SystemLink to this heading

I found this to be an extremely interesting talk.

  • Unknowingly shipped effect system with 1.0
  • async, const, ? operator, unsafe, yield are effects.
  • Effect mismatches are commonly known as “function coloring problem”
  • Proposal to avoid effect exponential blowup by introduce effect-generics
  • Effect-Generic Trait Definitions
    • we can no longer be generic over the traits though if the return types would be different?
  • Effect-Generic Types & Bounds
  • Carried Effects - affect types: async, yeild, ?
  • Uncarried Effects - don’t affect types. const, unsafe
  • const is already generic effect, since const fn are not always executed const.

RFC(s) coming sometime in 2024.

Fine, I’ll just make my own stable ABI, with compact sum-types and stable rustcLink to this heading

  • Plugins:
    • IPC plugins:
      • great isolations
      • easily transfered to RPC
      • requires serialization
    • Dynamically Linked plugins:
      • no isolation
      • no serialization
      • has to be ABI compatible with the host
  • -Z randomize-layout
    • Solana: could we use this to find some remaining spots where our tests are relying on layout when they shouldn’t be?
  • stabby crate for rust >=1.65
    • potentially interesting, but screws up matching
  • abi_stable
  • RFC 3470: crABI
  • RFC 3435: #[export]
  • ABI stability is colored, all composed types need to be stable.
  • Some options:
    • Cargo.toml - specify a default ABI
    • expand RFC 3434 to allow specifying the ABI of exported type

Overall dynamic linking in Rust needs to be improved.

How Powerful is Const?Link to this heading

Also found this talk very interesting, and it was broken into a few parts with basic overview of const, and then some more advanced const usages.

BasicsLink to this heading

  • Composable
  • MIRI - Mid-level Intermediate Representation Interpreter
graph LR; Rust --> MIR --> LLVM[LLVM IR] --> Mach[Machine Code]
  • Const is a compile-time feature.
  • Can be used to initialize statics
  • Const generics
  • Can do logic & loops at compile time
  • const _ = assert!(...)
    • I didn’t know this was possible. Neat!

More AdvancedLink to this heading

  • parsing, string transcoding are also possible
  • slice concatenation
    • append a null byte at the end of a string slice for use in C at compile time
  • const_format, impls, condtype
    • some interesting crates doing things at compile time
    • condtype seems really interesting
  • condtype
    • can do type-level conditionals, like larger of u64 or usize
  • -Zunleash-the-miri-inside-you
    • what the hell is this?
    • it’s a flag to enable const evaluation in more places
    • however, it’s not stable and will probably crash the compiler

Rust in the Wild: A Factory Control System From ScratchLink to this heading

The presentation of this talk was really well done.

  • Story in building a factory control system at AMP robotics
    • AMP robotics: recycling robots
  • Neural network to identify recyclables
    • off the shelf GPUs
    • better than human accuracy
  • Uses C++ for control system to integrate neural network with sortation robots
  • That was used to retrofit existing recycling facilities
  • Set out to build a new system, built around the neural network, from scratch
  • 24/7 operation
  • 20k pounds per hour
  • 6 months to build…in the middle of the pandemic
  • None of them knew Rust, C++ was what they were familiar
    • python was not going to fast enough
    • C++ developer velocity would be too slow
    • screw it! let’s try Rust
  • Built the central control system, which was high level:
    • did not touch safety features of the factory
  • Facility used 1 MW of power
    • that’s a lot of power, holy shit
  • Everything on Ethernet
    • >20 Gbps of data
    • packet captors help logging
    • common physical layer
  • Gaming PC hacks because servers arrived late
  • Used a microservices architecture
    • Better to have used aysnc and actors
  • It worked well!
    • 1/3 the time
    • 1/2 the developers
    • 1/10 the number of bugs
    • ^ compared to estimates in C++

Closing Keynote - Too many cooks or not enough kitchens?Link to this heading

Talk about open communities.

5-8 is the optimal team size. Lots of research on this.

  • Big enough for different perspectives
  • Small enough for:
    • feeling of shared ownership
    • opportunities to fully participate
    • logistics management
    • deep understanding of others positions
    • relationships => feel psychologically safe
  • Not much research on this so far for distributed teams though
  • 1972 - The Tyranny of Structurelessness
    • any group has a structure, just a question about whether it’s visible
  • Software companies:
    • informal
    • formal
    • value-creating
  • More structure interactions between teams
    • Team APIs!
  • Ostrom:
    • Clear group boundaries
    • … 7 others I couldn’t read fast enough!
    • I wonder how well Solana community and blockchain principals map to this
  • Internal structure of Labs?
    • We have small teams
    • Not sure there are clear boundaries between groups/teams though