Skip to content

Improve compressed stream handling - #3142

Merged
karussell merged 5 commits into
graphhopper:masterfrom
otbutz:skadi_gzip
Mar 26, 2025
Merged

karussell merged 5 commits into
graphhopper:masterfrom
otbutz:skadi_gzip

Conversation

@otbutz

@otbutz otbutz commented Mar 12, 2025 •

Copy link
Copy Markdown
Contributor

The default buffer size for GZIPInputStream and InflaterInputStream is only 512 bytes, resulting in many tiny OS read calls.

I also replaced all custom InputStream to OutputStream piping with InputStream.transferTo(OutputStream) calls.

grafik

@otbutz

otbutz commented Mar 12, 2025

Copy link
Copy Markdown
Contributor Author

Local testing with a large gzipped file shows a performance improvement of around 25%

@ratrun

ratrun commented Mar 12, 2025

Copy link
Copy Markdown
Contributor

Local testing with a large gzipped file shows a performance improvement of around 25%

Seems to apply only for one specific elevation provider, but such high improvements are always nice.

@otbutz

otbutz commented Mar 14, 2025

Copy link
Copy Markdown
Contributor Author

Seems to apply only for one specific elevation provider

SRTM uncompression should also be around 10% faster now.

}
os.flush();
GZIPInputStream gzis = new GZIPInputStream(is, 8 * 1024);
BufferedInputStream buff = new BufferedInputStream(gzis, 16 * 1024);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is that double the size of the gzip input stream? could it be the same?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I played a bit with the buffer sizes and this combination yielded the best results. It's also what Kafka is using: https://github.com/apache/kafka/pull/4537/files

@karussell karussell Mar 20, 2025 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, interesting. But the question "How was the default buffer size chosen?" was left unanswered there too.

Anyway...not that important. Let's just copy that, especially when you say you got the best results :)

@karussell karussell added this to the 11.0 milestone Mar 26, 2025
@karussell
karussell merged commit 4e7b5d4 into graphhopper:master Mar 26, 2025
@karussell

Copy link
Copy Markdown
Member

Thank you!

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.

3 participants