Hello, I'm an experienced C++ programmer and a programming language enthusiast. I'm new to Swift. I just started learning about the language a few days ago and for the most part I love what I see. However, there's one problematic issue with performance. That is, that reference counting must be an atomic operation and requires a mutex. This would absolutely destroy performance in the types of programs that I write. I realize that there is an -assume-single-threaded option that can be passed to the swift compiler, but I don't think that is a complete solution, as it completely prevents me from using threads with class types.
Instead, what if there was a way to make only certain class objects in Swift single threaded while the default would use thread safe atomic reference counting? Maybe with a keyword like single_threaded or unshared or something like that? If I could tell the compiler that only certain objects were to be treated as single threaded, this would allow me to write high performance single threaded code and provide a means for me to do threading with class objects as well. For the best performance, the single threaded feature would need to be part of the type system, so there would need to be single threaded strong references and single threaded weak references. For consistency, a single threaded reference could not be copied to a regular thread safe reference or vice versa.
I realize I'm new to the language so if any of what I said sounds juvenile or uninformed please forgive me. I am interested to hear any thoughts or responses regarding this idea. Swift seems to me to be an all around amazing language, but I write high performance code and it seems that this problem in particular would be a show stopper for me when considering using the language.