-
Notifications
You must be signed in to change notification settings - Fork 102
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
Vec<Vec<T>> is inefficient #54
Labels
Milestone
Comments
Tiled's map format is kinda a pain for actually drawing stuff anyway, so if it matters I'd personally just use the |
Closed
bjorn
added a commit
to bjorn/rs-tiled
that referenced
this issue
Jan 24, 2022
This simplifies code and should be better on memory usage since it is less fragmented. Also added `width` and `height` attributes to `Layer`. Closes mapeditor#54
bjorn
added a commit
to bjorn/rs-tiled
that referenced
this issue
Jan 24, 2022
This simplifies code and should be better on memory usage since it is less fragmented. Also added `width` and `height` attributes to `Layer`. Closes mapeditor#54
bjorn
added a commit
that referenced
this issue
Jan 24, 2022
This simplifies code and should be better on memory usage since it is less fragmented. Also added `width` and `height` attributes to `Layer`. Closes #54
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It would be better to index a single large Vec as a 2D object, Row Order preferably (As this is the convention used by C and most other languages)
https://stackoverflow.com/a/2151141
Why this is inefficient:
Simple, really: Heap fragmentation. This allocates one new vector for each column of the vector. I.e. in the case of
Layer
, a large layer, say, 1024x1024, will have 1025 length 1024 vectors allocated. A single vector is nicer to the kernel (One big allocation vs multiple small ones), and for iterating over the whole map, it performs quite a bit better, as the CPU can easily predict the access pattern on it's own without assistance.The text was updated successfully, but these errors were encountered: