# Possible Rust-specific optimizations

**URL:** <https://users.rust-lang.org/t/possible-rust-specific-optimizations/79895>\
**Category:** uncategorized\
**Created:** [August 15, 2022, 9:42am UTC](https://users.rust-lang.org/t/possible-rust-specific-optimizations/79895 "2022-08-15T09:42:23Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![H2CO3](https://avatars.discourse-cdn.com/v4/letter/h/b5ac83/32.png) [@H2CO3](https://users.rust-lang.org/u/H2CO3)\
**Post date:** [August 15, 2022, 11:01am UTC](https://users.rust-lang.org/t/possible-rust-specific-optimizations/79895/3 "2022-08-15T11:01:02Z")

</div>

> [@Heliozoa](#):
>
> I couldn't tell you how exactly it helps though

It allows the compiler to eliminate loads when an immutable place is known not to alias with any mutable ones:

```rust
fn print_and_increment(x: &i32, y: &mut i32) {
    println!("x = {}", x);
    *y += 1;
    println!("x = {}", x);
}

```

Since x and y are known not to alias, the compiler can assume `*x` doesn't change when something writes through `y`, so it can cache `*x` in a register instead of reloading it from main memory upon printing it for the second time.

---

_[View the full topic](https://users.rust-lang.org/t/possible-rust-specific-optimizations/79895)._
