From 083446efa5163791df235fd70f3f1d38bdd8b832 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Sat, 22 Nov 2025 19:57:25 +0100 Subject: don't offer brotli content encoding That was good while we still had files saved brotli-compressed, but now it adds more overhead. --- fietsboek/views/detail.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/fietsboek/views/detail.py b/fietsboek/views/detail.py index 8ca7836..4af7994 100644 --- a/fietsboek/views/detail.py +++ b/fietsboek/views/detail.py @@ -6,7 +6,6 @@ import io import logging from html.parser import HTMLParser -import brotli from markupsafe import Markup from pyramid.httpexceptions import ( HTTPFound, @@ -134,18 +133,17 @@ def gpx(request): wanted_filename = f"{track.id}.gpx" content_disposition = f'attachment; filename="{wanted_filename}"' gpx_data = track.gpx_xml() - # We can be nice to the client if they support it, and deliver the gzipped - # data straight. This saves decompression time on the server and saves a - # lot of bandwidth. - accepted = request.accept_encoding.acceptable_offers(["br", "gzip", "identity"]) + # We used to offer brotli compression here as well, but brotli is too + # inefficient to do on-the-fly. That was only useful while we had the data + # stored brotli-compressed. For comparison, a track with ~50k points: + # identity -- 2.4s -- 5.49 MiB + # gzip -- 2.5s -- 657.53 KiB + # brotli -- 12s -- 389.45 KiB + # So yes, brotli does give better compression than gzip, but the time is + # not worth paying for. + accepted = request.accept_encoding.acceptable_offers(["gzip", "identity"]) for encoding, _qvalue in accepted: - if encoding == "br": - data = brotli.compress(gpx_data) - response = Response(data, content_type="application/gpx+xml", content_encoding="br") - break if encoding == "gzip": - # gzip'ed GPX files are so much smaller than uncompressed ones, it - # is worth re-compressing them for the client data = gzip.compress(gpx_data) response = Response(data, content_type="application/gpx+xml", content_encoding="gzip") break -- cgit v1.2.3