Commit 8a996e3
authored
Use HashSet to track GraphicsDevice resources (MonoGame#9027)
<!--
Are you targeting develop? All PRs should target the develop branch
unless otherwise noted.
-->
Improves performance of `GraphicsDevice.RemoveResourceReference` (and by
extension `GraphicsResource.Dispose`) when there are a lot of resources.
<!--
Please try to make sure that there is a bug logged for the issue being
fixed if one is not present.
Especially for issues which are complex.
The bug should describe the problem and how to reproduce it.
-->
### Description of Change
`List<T>.Remove(T item)` needs to iterate every item of the list to find
the one to remove, then shift items when removing from the middle.
HashSet<T> has much faster deletion, at the cost of a slightly slower
insert.
My specific example had over 30000 resources, and triggered large
stutters when clearing a cache with around 4000 recently allocated
items. It was iterating approximately 120000000 resources removing these
entries, since they would be at the end of the list.
My test case was a little extreme since I was scrolling a map with a
huge number of unique models that stream in+out, but it's an easy
improvement to make.
<!--
Enter description of the fix in this section.
Please be as descriptive as possible, future contributors will need to
know *why* these changes are being made.
For inspiration review the commit/PR history in the MonoGame repository.
-->1 parent bcc73c6 commit 8a996e3
2 files changed
Lines changed: 31 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
154 | 155 | | |
155 | 156 | | |
156 | 157 | | |
157 | | - | |
| 158 | + | |
158 | 159 | | |
159 | 160 | | |
160 | 161 | | |
| |||
804 | 805 | | |
805 | 806 | | |
806 | 807 | | |
807 | | - | |
| 808 | + | |
808 | 809 | | |
809 | 810 | | |
810 | 811 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
852 | 852 | | |
853 | 853 | | |
854 | 854 | | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
855 | 882 | | |
856 | 883 | | |
0 commit comments