status-im / nim-chronos

Chronos - An efficient library for asynchronous programming
https://status-im.github.io/nim-chronos/docs/chronos
Apache License 2.0
353 stars 51 forks source link

Write to `Future.internalValue` directly in macro-translated code #452

Open arnetheduck opened 11 months ago

arnetheduck commented 11 months ago

Although https://github.com/status-im/nim-chronos/pull/418 was ultimately not merged, it contains an idea to improve performance in general: instead of allocating a separate var result that gets injected, it instead injects a template result = fut.internalValue which means we use the in-flight future as temporary storage for results instead of a local variable thus saving memory, zero:es and copies.

The technique is interesting but needs to be tested against https://github.com/nim-lang/Nim/issues/22605 of which it may run afoul (along with other correctness / observability issues).