Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Rust High Performance
Rust High Performance

Rust High Performance: Learn to skyrocket the performance of your Rust applications

eBook
$27.98 $39.99
Paperback
$48.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Rust High Performance

Extra Performance Enhancements

Once your application avoids common performance bottlenecks, it's time to move to more complex performance improvements. Rust has many options that allow you to improve the performance of your code by using lesser-known APIs. This will give you parity with C/C++ and, in some scenarios, it can even improve the speed of most of the fastest C/C++ scripts.

In this chapter, we will be looking into the following topics:

  • Compile-time checks
  • Compile-time state machines
  • Extra performance enhancements, such as using closures for avoiding runtime evaluation
  • Unstable sorting
  • Map hashing
  • Standard library collections

Compile-time checks

Rust has an amazing type system. It's so powerful that it is Turing-complete by itself. This means that you can write very complex programs just by using Rust's type system. This can help your code a lot, since the type system gets evaluated at compile time, making your runtime much faster.

Starting from the basics, what do we mean by the type system? Well, it means all those traits, structures, generics, and enums you can use to make your code very specialized at runtime. An interesting thing to know is the following: if you create a generic function that gets used with two different types, Rust will compile two specific functions, one for each type.

This might seem like code duplication but, in reality, it is usually faster to have a specific function for the given type than to try to generalize a function over multiple ones. This also allows...

Extra performance tips

Compile-time checks are not the only place where you can benefit from a performance enhancement at no cost. While in Chapter 1Common Performance Pitfallswe saw the common errors people write in Rust, we left the most advanced tips and tricks for this chapter.

Using closures to avoid runtime evaluation

Sometimes, it might seem natural to write code that does not perform as fast as expected. Many times, this is due to Rust doing some extra computations at runtime. An example of an unnecessary computation that someone could write is the following:

    let opt = Some(123);
let non_opt = opt.unwrap_or(some_complex_function());

I have intentionally made this example simply because a real...

Standard library collections

Rust's standard library has eight different collection types in the std::collections module. They are divided into sequences, maps, sets, and a binary heap that does not fit in any group. The most well known ones are arguably HashMap and Vec, but each of them has a use case, and you should know about them to use the proper one in each moment.

The official standard library documentation is really good, so you should check it thoroughly. In any case, though, I will introduce the types so that you can familiarize yourself with them. Let's start with sequences.

Sequences

The most-used dynamic sequence in Rust and in most languages is the vector, represented in Rust as Vec. You can add...

Summary

In this chapter, you learned how to use compile-time checks to your advantage. You learned how Rust's type system can help you create complex and safe behaviour without runtime overhead. You learned how to create state machines and how to make your code less error-prone.

You also learned about some extra performance enhancements that complement those of Chapter 1Common Performance Pitfalls. You learned about unstable sorting and map hashing, including perfect hash functions created at compile time, and how to create compile-time hash maps that will have no runtime overhead.

Finally, you learned about the collections in the standard library, how they are classified, and which type of collection you should use depending on the situation. You learned about sequences, maps, and sets, and how they can be adapted for your code.

In Chapter 3Memory Management...

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • • Understand common performance pitfalls and improve the performance of your applications.
  • • Get to grips with parallel programming and multithreading with Rust.
  • • Learn metaprogramming in Rust.

Description

This book teaches you how to optimize the performance of your Rust code so that it is at the same level as languages such as C/C++. You'll understand and fi x common pitfalls, learn how to improve your productivity by using metaprogramming, and speed up your code. You will master the features of the language, which will make you stand out, and use them to greatly improve the efficiency of your algorithms. The book begins with an introduction to help you identify bottlenecks when programming in Rust. We highlight common performance pitfalls, along with strategies to detect and resolve these issues early. We move on to mastering Rust's type system, which will enable us to optimize both performance and safety at compile time. You will learn how to effectively manage memory in Rust, mastering the borrow checker. We move on to measuring performance and you will see how this affects the way you write code. Moving forward, you will perform metaprogramming in Rust to boost the performance of your code and your productivity. Finally, you will learn parallel programming in Rust, which enables efficient and faster execution by using multithreading and asynchronous programming.

Who is this book for?

This book is for Rust developers keen to improve the speed of their code or simply to take their skills to the next level.

What you will learn

  • • Master tips and tricks to improve performance of your code
  • • Learn how to identify bottlenecks in your Rust applications
  • • Discover how to profile your Rust software
  • • Understand the type system in order to create compile-time optimizations
  • • Master the borrow checker
  • • Learn metaprogramming in Rust to avoid boilerplate code
  • • Discover multithreading and work stealing in Rust
  • • Understand asynchronous programming in Rust

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Mar 28, 2018
Length: 272 pages
Edition : 1st
Language : English
ISBN-13 : 9781788478236
Category :
Languages :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Mar 28, 2018
Length: 272 pages
Edition : 1st
Language : English
ISBN-13 : 9781788478236
Category :
Languages :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 146.97
Rust High Performance
$48.99
Rust Standard Library Cookbook
$48.99
Hands-On Concurrency with Rust
$48.99
Total $ 146.97 Stars icon

Table of Contents

12 Chapters
Common Performance Pitfalls Chevron down icon Chevron up icon
Extra Performance Enhancements Chevron down icon Chevron up icon
Memory Management in Rust Chevron down icon Chevron up icon
Lints and Clippy Chevron down icon Chevron up icon
Profiling Your Rust Application Chevron down icon Chevron up icon
Benchmarking Chevron down icon Chevron up icon
Built-in Macros and Configuration Items Chevron down icon Chevron up icon
Must-Have Macro Crates Chevron down icon Chevron up icon
Creating Your Own Macros Chevron down icon Chevron up icon
Multithreading Chevron down icon Chevron up icon
Asynchronous Programming Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
(3 Ratings)
5 star 33.3%
4 star 0%
3 star 0%
2 star 66.7%
1 star 0%
Captain Yossarian May 11, 2020
Full star icon Full star icon Full star icon Full star icon Full star icon 5
One of the best Rust book I have ever read. This books is for you if you know Rut syntax and main principles of the language.Before reading this book I thought I'm strong beginner, but on 10th page I have understand that I'm still dont know Rust.
Amazon Verified review Amazon
jesion Oct 27, 2020
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2
This book does not deliver on its promise. I was expecting deep-dive analysis of Rust code in specific situations. To my disappointment, performance aspects are covered only in the first 1/3 of whole book, And even there the topics covered are mostly trivial and well known to even non-advanced Rust users, lacking any serious analysis. Plus some basics of performance aspects generic to software development (tools, CPU architecture), not specific to Rust.The rest of the book is a random selection of various topics with very few loose references to performance (macros???).I'm not sure whom this book is for. Beginners will start somewhere else as this book does not introduce the language. Anyone who passed the introduction to Rust and got some minimal practics, will not find much interesting information here, either.
Amazon Verified review Amazon
Blackmagic Jun 06, 2023
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2
The first few chapters are ok, cover some rust specific topics like iterators, memory alignment, clippy etc.Then the parts about profiling and benchmarks are so high level they are pointless. The bench marking misses anything to do with issues relating to micro-benchmarking and compiler optimizations changing results. The later sections about threading and async could just be wikipedia articles.I get the feeling the author started with a lot of energy and then just wrote the second half of the book as quickly as possible.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.