Rust for Rustaceans by Jon Gjengset
Author:Jon Gjengset [Gjengset, Jon]
Language: eng
Format: epub, mobi, pdf
ISBN: 9781718501867
Published: 2021-09-28T00:00:00+00:00
The Size of Generators
The data structure used to back a generatorâs state must be able to hold the combined state at any one yield point. If your async fn contains, say, a [u8; 8192], those 8KiB must be stored in the generator itself. Even if your async fn contains only smaller local variables, it must also contain any future that it awaits, since it needs to be able to poll such a future later, when poll is invoked.
This nesting means that generators, and thus futures based on async functions and blocks, can get quite large without any visible indicator of that increased size in your code. This can in turn impact your programâs runtime performance, since those giant generators may have to be copied across function calls and in and out of data structures, which amounts to a fair amount of memory copying. In fact, you can usually identify when the size of your generator-based futures is affecting performance by looking for excessive amounts of time spent in the memcpy function in your applicationâs performance profiles!
Finding these large futures isnât always easy, however, and often requires manually identifying long or complex chains of async functions. Clippy may be able to help with this in the future, but at the time of writing, youâre on your own. When you do find a particularly large future, you have two options: you can try to reduce the amount of local state the async functions need, or you can move the future to the heap (with Box::pin) so that moving the future just requires moving the pointer to it. The latter is by far the easiest way to go, but it also introduces an extra allocation and a pointer indirection. Your best bet is usually to put the problematic future on the heap, measure your performance, and then use your performance benchmarks to guide you from there.
Download
Rust for Rustaceans by Jon Gjengset.mobi
Rust for Rustaceans by Jon Gjengset.pdf
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Hello! Python by Anthony Briggs(9372)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9341)
The Mikado Method by Ola Ellnestam Daniel Brolund(9307)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(7851)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7401)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7321)
Grails in Action by Glen Smith Peter Ledbrook(7295)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7115)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(5956)
Kotlin in Action by Dmitry Jemerov(4637)
Hands-On Full-Stack Web Development with GraphQL and React by Sebastian Grebe(3879)
Functional Programming in JavaScript by Mantyla Dan(3723)
Learning Java by Patrick Niemeyer & Daniel Leuck(2871)
Mastering Python for Finance by Weiming James Ma;(2838)
Learning React: Functional Web Development with React and Redux by Banks Alex & Porcello Eve(2835)
WordPress Plugin Development Cookbook by Yannick Lefebvre(2596)
Windows APT Warfare by Sheng-Hao Ma(2587)
Mastering Java 9 by Dr. Edward Lavieri(2572)
Architecting Modern Java EE Applications: Designing lightweight, business-oriented enterprise applications in the age of cloud, containers, and Java EE 8 by Daschner Sebastian(2557)