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

Vec<Vec<T>> is inefficient #54

Closed
moonheart08 opened this issue May 15, 2019 · 1 comment · Fixed by #128
Closed

Vec<Vec<T>> is inefficient #54

moonheart08 opened this issue May 15, 2019 · 1 comment · Fixed by #128
Milestone

Comments

@moonheart08
Copy link

moonheart08 commented May 15, 2019

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.

@icefoxen
Copy link
Contributor

Tiled's map format is kinda a pain for actually drawing stuff anyway, so if it matters I'd personally just use the tiled crate as a loader and copy everything into your own structure for drawing. I had to do this anyway to get nicer tile lookups, so, probably not a big deal.

@bjorn bjorn linked a pull request Dec 23, 2021 that will close this issue
@aleokdev aleokdev added this to the 0.10.0 milestone Dec 23, 2021
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
Projects
None yet
4 participants