Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Ask HTTP implementations not to do content decoding #3886

Open

Description

@jfirebaugh

We want to store compressed resources in the offline database. Our implementation ends up decompressing and then recompressing. Instead, we should ask NSURLSession, curl, and OkHttp to give us the gzipped body back, put the compressed body directly into the database, and only then decompress it for downstream consumers.

Specifically, we need to tell our HTTP libraries to as for and pass through gzip content encoding, since that's the only format we know how to decompress.

If we get back an uncompressed body (i.e. the server doesn't support content encoding), we should still try to compress it before storing it in the database.

This will improve performance of offline downloading significantly. Right now almost all of the CPU used during offline downloads goes toward compression and decompression, neither of which is necessary.

Activity

  1. added
    performance
    on Feb 10, 2016
  2. self-assigned this
    on Feb 11, 2016
  3. jfirebaugh commented on Feb 11, 2016

    @jfirebaugh
    ContributorAuthor
    • ✅ OkHttp: If you add your own Accept-Encoding: gzip header to the request, you take responsibility for decoding.
    • ✅ Curl: "You can also opt to just include the Accept-Encoding: header in your request with CURLOPT_HTTPHEADER but then there will be no automatic decompressing when receiving data."
    • ❌ NSURLSession: Apparently not possible to take responsibility for decoding. 😭
  4. kkaefer commented on Feb 11, 2016

    @kkaefer
    Member

    This is indeed the right approach (but it still means we'll have to decompress in the SQLite source, and ideally move that to another thread).

    Regarding NSURLSession, I tried http://stackoverflow.com/a/16705063/331379 and indeed got the compressed response, but of course it's a private API so we can't use it :(

  5. tmpsantos commented on Feb 11, 2016

    @tmpsantos
    Contributor

    Agreed, it is the right approach. ✅ for Qt, it is done the same way as OkHttp.

    I also second @kkaefer that we should move decompress to a separate thread.

  6. 1ec5 commented on Mar 16, 2016

    @1ec5
    Contributor

    It’s pretty low-level, but does NSInputStream pass through gzip-encoded data?

  7. incanus commented on Jul 19, 2016

    @incanus
    Contributor

    I wonder if modifying NSURLSession.sessionConfiguration.requestCachePolicy would in effect sidestep this, if specifically set to not cache automatically (presuming that automatic caching has a hand in decoding for its own purposes).

  8. added
    Core
    on May 30, 2017
  9. halset commented on Jun 9, 2017

    @halset
    Contributor

    If this is ever fixed on iOS, how would this change the Mapbox APIs? Would you add a compressed-flag to mbgl::Response?

    The reason I ask is that I insert lots of tiles from a SQLite file that I download from my server. This db has the same schema as the Mapbox GL cache with some of the tiles/resources compressed. I currently use a lot of cpu to decompress and recompress during import when I really should just keep the data and the compressed flag from the external SQLite file.

  10. jfirebaugh commented on Jun 9, 2017

    @jfirebaugh
    ContributorAuthor

    There wouldn't be any changes to public APIs or the (private) database schema.

  11. fabian-guerra commented on Jun 12, 2017

    @fabian-guerra
    Contributor

    @1ec5 and I asked Apple engineers about accessing the underlaying compressed file (at the networking lab). They confirmed what we already know; is not possible. They asked us why would we want that and we explained the use case to what they suggested that we should file radars in order to get it done. I don't think this is something that is going to be solved soon. What we could do is for each of us that has an apple dev account file a radar asking for this.

  12. 1ec5 commented on Jun 12, 2017

    @1ec5
    Contributor

    What we could do is for each of us that has an apple dev account file a radar asking for this.

    Also note in the radar that it's a dupe of the radar in #3886 (comment).

  13. added
    archived
    on Nov 6, 2018
  14. stale commented on Nov 30, 2018

    @stale

    This issue has been automatically detected as stale because it has not had recent activity and will be archived. Thank you for your contributions.

  15. removed
    archived
    on Nov 30, 2018
  16. added
    archived
    on May 29, 2019
  17. stale commented on May 29, 2019

    @stale

    This issue has been automatically detected as stale because it has not had recent activity and will be archived. Thank you for your contributions.

  18. removed
    archived
    on May 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Coreofflineperformance

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions