Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance enhancement #7

Open
Quistar-LAB opened this issue Jun 1, 2021 · 2 comments
Open

Performance enhancement #7

Quistar-LAB opened this issue Jun 1, 2021 · 2 comments

Comments

@Quistar-LAB
Copy link
Owner

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.

@Quistar-LAB
Copy link
Owner Author

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!

@Quistar-LAB
Copy link
Owner Author

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

@Quistar-LAB Quistar-LAB reopened this Jun 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant