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

Seeking leaks memory #82

Closed
maxnoe opened this issue May 9, 2019 · 2 comments
Closed

Seeking leaks memory #82

maxnoe opened this issue May 9, 2019 · 2 comments

Comments

@maxnoe
Copy link
Contributor

maxnoe commented May 9, 2019

Seeking on a zstandard stream reader causes the full file to be read into ram.

Minimal example:

$ head -c 500M /dev/urandom > test.dat
$ zstd test.dat
import zstandard as zstd
import os
import psutil

p = psutil.Process(os.getpid())
path = 'test.dat.zst'

reader = zstd.ZstdDecompressor().stream_reader(open(path, 'rb'))

chunk = reader.read(1)
while chunk:
    # seek 100 MB forward
    reader.seek(100 * 1024**2, 1)
    print(p.memory_info()[0] / 1024**2)
    chunk = reader.read(1)

Result:

114.1171875
214.1484375
314.1796875
414.2109375
514.2421875

If one only reads, only the currently read data is in RAM:

import zstandard as zstd
import os
import psutil

p = psutil.Process(os.getpid())
path = 'test.dat.zst'

reader = zstd.ZstdDecompressor().stream_reader(open(path, 'rb'))

chunk = reader.read(1)
while chunk:
    # seek one MB forward
    reader.read(100 * 1024**2)
    print(p.memory_info()[0] / 1024**2)
    chunk = reader.read(1)

Result

14.28515625
14.2890625
14.2890625
14.2890625
14.2890625
@indygreg
Copy link
Owner

indygreg commented May 9, 2019

This is definitely a bug. Thank you for reporting it.

@maxnoe
Copy link
Contributor Author

maxnoe commented May 10, 2019

Fixed in #83

indygreg pushed a commit that referenced this issue May 15, 2019
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

No branches or pull requests

2 participants