Optimizations

We will try to apply three optimizations to the code we created in the previous section:

  • We will try to reduce the blocking of a shared state.
  • We will reuse a value in a state by reference.
  • We will add caching of responses.

After we implement them, we will check the performance after the first two improvements, and later check it again with caching.

In the code of this section, we will implement all optimizations gradually, step by step, but if you downloaded the example from the GitHub repository of this book, you will find the following features in the Cargo.toml file of the project of this chapter:

[features]
default = []
cache = []
rwlock = []
borrow = []
fast = ["cache", "rwlock", "borrow"]

The code here uses features to provide you a capability to activate or deactivate any optimization separately. We see the following:

  • cache: activates the caching of requests
  • rwlock: uses RwLock instead of Mutex for State
  • borrow: reuses a value by reference

Let's implement all of these optimizations and apply all of them to measure differences in the performance.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.254.151