Skip to content

Performance enhancement #7

@Quistar-LAB

Description

@Quistar-LAB

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions