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

More efficient array creation #11468

Merged
merged 1 commit into from
Apr 30, 2024
Merged

More efficient array creation #11468

merged 1 commit into from
Apr 30, 2024

Conversation

Bond-009
Copy link
Member

  • Use new collection expressions to concat to existing arrays
  • Use Array.ConvertAll where possible
  • Replace .ToArray with .ToList where possible

(And yes, collection expressions are as fast/faster than manually creating and copying)

| Method | N    | Mean       | Error     | StdDev    | Gen0   | Allocated |
|------- |----- |-----------:|----------:|----------:|-------:|----------:|
| Magic  | 0    |   9.943 ns | 0.0780 ns | 0.0692 ns | 0.0004 |      32 B |
| Manual | 0    |  14.550 ns | 0.0883 ns | 0.0826 ns | 0.0004 |      32 B |
| Magic  | 1    |  10.365 ns | 0.0529 ns | 0.0494 ns | 0.0004 |      32 B |
| Manual | 1    |  15.433 ns | 0.1458 ns | 0.1364 ns | 0.0004 |      32 B |
| Magic  | 4    |  11.119 ns | 0.0906 ns | 0.0803 ns | 0.0004 |      32 B |
| Manual | 4    |  15.586 ns | 0.1641 ns | 0.1370 ns | 0.0004 |      32 B |
| Magic  | 64   |  15.337 ns | 0.0777 ns | 0.0649 ns | 0.0011 |      96 B |
| Manual | 64   |  20.924 ns | 0.2432 ns | 0.2275 ns | 0.0011 |      96 B |
| Magic  | 512  |  53.652 ns | 0.5195 ns | 0.4860 ns | 0.0065 |     544 B |
| Manual | 512  |  58.823 ns | 0.4412 ns | 0.3911 ns | 0.0064 |     544 B |
| Magic  | 2048 | 187.799 ns | 2.6503 ns | 2.4791 ns | 0.0248 |    2080 B |
| Manual | 2048 | 197.916 ns | 1.4985 ns | 1.4017 ns | 0.0248 |    2080 B |

* Use new collection expressions to concat to existing arrays
* Use Array.ConvertAll where possible
* Replace .ToArray with .ToList where possible
@crobibero crobibero merged commit 3feb3f8 into jellyfin:master Apr 30, 2024
14 checks passed
@Bond-009 Bond-009 deleted the array branch April 30, 2024 19:33
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

Successfully merging this pull request may close these issues.

4 participants