I've moved this to the compiler development section, since this is unrelated to server stuff. But I would say that if you're getting vastly different compile times results, you should file a bug on bugs.swift.org. If you can reference your implementation that causes the issue, or make a sample project that reproduces it, that'd be extremely helpful.
Although, one thing that it could be is the change in exclusivity checking between 4 and 5. I haven't dug into his code, but iirc, having final can aid in eliding some of the more conservative checking.
When the class isn't final, the property access to arr has to be dynamically dispatched and treated like a potentially-computed property, in case a subclass overrides it. In -O -wmo builds, though, we ought to notice later that there are no subclasses of the class in the program and inline the access. It's possible that that isn't happening for some reason, or that if so, the exclusive access marker calls are not optimized after the inlining happens. @Andrew_Trick, do you know if this is a known issue?
Thanks. The other major change in Swift 5 that comes to my mind is the switch to the coroutine model for the property ABI; maybe there's a limitation in the devirtualizer and/or inliner's handling of the coroutine here.
That retain_value prevents the COWArray pass from hoisting the array's
uniqueness check. That's expensive and also probably blocks any other
downstream loop optimizations.
It seems there are multiple points at which the optimizations fall
apart, but I think the starting point should be
Why does SILGen require the generalized accessor in WMO mode.
Why does using the generalized accessor (TestGlobalArr.arr!modify) cause an extra retain.