You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Cities Skylines uses .Net 3.5 Framework which is quite old and the CLR used does not support the CPU enhancements we have today, especially when it comes to SSE2 or AVX2 special instructions.
Drawing trees requires a lot of math, and with the original limit of 262144 trees, this wasn't too much of a problem, but with Unlimited Trees mods, we need to account for the possibly increased trees of up to millions.
Running a loop through 262144 is fast and can be completed within 50ms, but if its looped through 1 million trees, then that 50ms will become 200ms and maybe more due to branching and threading synchronizations.
My proposed solution is to go around this and add a wrapper to my mod to create access to SSE2 and AVX2. This doesn't come with a caveat and that is, there is a performance hit when switching between managed and unmanaged codes. BUT, I'm certain that the switch will be negligible compared to the current IL codes being generated by the old CLR2.0 (.Net3.5 Framework).
An example would be Unity functions Mathf.Min/Max. These functions, when compiled into IL results in around 10 instructions with branches. But if using AVX or SSE special instructions, the same results can be achieved using just 3 assembly instructions.
That would be a ~5x improvement over the original methods. And worth considering.
The text was updated successfully, but these errors were encountered:
The latency introduced when moving from managed to unmanaged is just too big, making this consideration unworthy of further investigation. The way Cities Skylines draws trees using grids looped inside a nested loop makes it very hard to avoid multiple transfers between managed and unmanaged. Closing!
I'm resorting to the traditional methods in increasing performance. Unrolling loops manually and removing redundant checks.
Need to profile in multiple scenarios to see the effect
Cities Skylines uses .Net 3.5 Framework which is quite old and the CLR used does not support the CPU enhancements we have today, especially when it comes to SSE2 or AVX2 special instructions.
Drawing trees requires a lot of math, and with the original limit of 262144 trees, this wasn't too much of a problem, but with Unlimited Trees mods, we need to account for the possibly increased trees of up to millions.
Running a loop through 262144 is fast and can be completed within 50ms, but if its looped through 1 million trees, then that 50ms will become 200ms and maybe more due to branching and threading synchronizations.
My proposed solution is to go around this and add a wrapper to my mod to create access to SSE2 and AVX2. This doesn't come with a caveat and that is, there is a performance hit when switching between managed and unmanaged codes. BUT, I'm certain that the switch will be negligible compared to the current IL codes being generated by the old CLR2.0 (.Net3.5 Framework).
An example would be Unity functions Mathf.Min/Max. These functions, when compiled into IL results in around 10 instructions with branches. But if using AVX or SSE special instructions, the same results can be achieved using just 3 assembly instructions.
That would be a ~5x improvement over the original methods. And worth considering.
The text was updated successfully, but these errors were encountered: