View Issue Details

IDProjectCategoryView StatusLast Update
0009284Talerexchangepublic2025-08-31 17:09
Reporterfefe Assigned ToChristian Grothoff Resolution deadline
ImplementerReviewer 
Release signed byDeployed by 
VerifierCommunicator 
Data protection authority notification requiredNo  
CSIRT notification requiredNo  
Estimated effort (hours)Actual effort (hours)0 
Fast-trackNo
Work packagenone
PrioritynoneSeveritytrivialReproducibilityhave not tried
Status closedResolutionopen 
Product Versiongit (master) 
Target Version1.0 stretch goalsFixed in Version1.0 stretch goals 
Summary0009284: inefficient web serving in exchange mhd_spa
DescriptionThe function build_webui opens a file, reads a copy of it into malloced memory (without size restrictions), then calls zlib compress on the buffer. This appears to happen also for pre-compressed files like jpeg and png.

This is very inefficient.

Proposal 1: This is all for static files, so why not pre-compress them? Put foo.html.gz next to foo.html and if the browser supports gzip compression, just serve that file instead. No CPU cycles wasted on compression.

Proposal 2: At least use mmap instead of malloc+read. Doing malloc+read puts unnecessary pressure on the virtual memory system for no gain. The only situation where malloc+read has an advantage is if you expect a filesystem race where someone truncates a file while you have it mmapped. This does not appear to be a realistic scenario here. Downside: you need to track how to free the buffer then and can't just call free on it.
TagsNo tags attached.

Required notifications

Address or linkRemarkAdded byNotifiedActions

Activities

Christian Grothoff

2024-10-22 03:53

manager   ~0023555

mmap always uses whole pages. That's actually inefficient for small files. Here, we do often have rather small files. So if we do this it'd mostly make sense for the one large file.

We could indeed have pre-compressed files on disk, but that'd put more requirements on the installation process. You'd either have to put both compressed and uncompressed into say the Debian package, or have the installer include extra steps to do the compression.

A bigger benefit with compression-on-disk would be that we could actually use sendfile() and avoid mmap/malloc entirely. But, regardless, optimization issue of no practical relevance in the medium term IMO.

Christian Grothoff

2025-06-21 22:42

manager   ~0025299

https://packages.debian.org/bookworm/pigz can be used to generate zlib output (deflate).

Christian Grothoff

2025-06-22 21:29

manager   ~0025311

dev/grothoff/bug9284 contains a preliminary patch.
Needs more testing, and Debian packages should be modified to install pre-compressed resource files for the SPAs.

Christian Grothoff

2025-07-03 09:26

manager   ~0025391

Testing done, looks fine, added postinst steps to challenger, exchange (incl. auditor) and merchant to compress SPA resources after unpacking (so the Deb packages don't increase in size from the compressed versions).

Issue History

Date ModifiedUsernameFieldChange
2024-10-21 12:30fefeNew Issue
2024-10-21 12:30fefeStatusnew => assigned
2024-10-21 12:30fefeAssigned To => Christian Grothoff
2024-10-22 03:53Christian GrothoffNote Added: 0023555
2024-10-22 03:53Christian GrothoffPrioritynormal => none
2024-10-22 03:53Christian GrothoffSeverityminor => trivial
2024-10-22 03:53Christian GrothoffProduct Version => git (master)
2024-10-22 03:53Christian GrothoffTarget Version => post-1.0
2024-10-22 04:55Christian GrothoffAssigned ToChristian Grothoff =>
2024-10-22 04:55Christian GrothoffStatusassigned => implementing
2024-11-12 22:56Christian GrothoffTarget Versionpost-1.0 => 1.4
2024-12-07 22:03Christian GrothoffTarget Version1.4 => 1.3
2025-04-17 20:49Christian GrothoffTarget Version1.3 => post-1.0
2025-06-21 22:21Christian GrothoffAssigned To => Christian Grothoff
2025-06-21 22:21Christian GrothoffStatusimplementing => assigned
2025-06-21 22:42Christian GrothoffNote Added: 0025299
2025-06-22 21:29Christian GrothoffNote Added: 0025311
2025-07-03 09:26Christian GrothoffNote Added: 0025391
2025-07-03 09:26Christian GrothoffStatusassigned => informing
2025-07-03 09:26Christian GrothoffFixed in Version => 1.0 stretch goals
2025-07-03 09:26Christian GrothoffTarget Versionpost-1.0 => 1.0 stretch goals
2025-08-31 17:09Christian GrothoffStatusinforming => closed