Yep, good idea. I figured instead of using TaskLocal.withValue
I could simply use an initial value for my local task variable and it will be allocated only when used first time and only once per task, so the TaskLocal.withValue
speed is not important:
class Foo {
var value = 0
@TaskLocal static var foo = Foo()
}
...
Foo.foo.value = 123
I measured the task local variable access performance on ARM and it gave me ~32 nanoseconds per access, which is not bad at all. Those accesses are used in both "try" and "throw" of my bespoke "unchecked exceptions" implementation (which core is remarkably short - just 25 lines!).