1

[RFC 2011] Optimize non-consuming operators by c410-f3r · Pull Request #98337 ·...

 1 year ago
source link: https://github.com/rust-lang/rust/pull/98337
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Contributor

@c410-f3r c410-f3r commented 17 days ago

edited

Tracking issue: #44838
Fifth step of #96496

The most non-invasive approach that will probably have very little to no performance impact.

Current behaviour

Captures are handled "on-the-fly", i.e., they are performed in the same place expressions are located.

// `let a = 1; let b = 2; assert!(a > 1 && b < 100);`

if !(
  { ***try capture `a` and then return `a`*** } > 1 && { ***try capture `b` and then return `b`*** } < 100
) {
  panic!( ... );
}

As such, some overhead is likely to occur (Specially with very large chains of conditions).

New behaviour for non-consuming operators

When an operator is known to not take self, then it is possible to capture variables AFTER the condition.

// `let a = 1; let b = 2; assert!(a > 1 && b < 100);`

if !( a > 1 && b < 100 ) {
  { ***try capture `a`*** }
  { ***try capture `b`*** }
  panic!( ... );
}

So the possible impact on the runtime execution time will be diminished.

r? @oli-obk

All reactions

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK