Skip to content

SVG Export size reductions #6359

Open
Open

Description

@bluss

Description

Hi, I recently ran scour to reduce size of these typst outputs (to save space in typst/packages). The following are ideas for reducing size of SVG outputs:

  • Use unique minimal ids
    • Typst 0.13.1 produces symbols with ids like id="gAE8F30B35D6A8EB54F09046949FB529D"and scour replaces it with id="n" and so on
    • This saved 8% file size on the two text filled tables
    • Unclear if viable for Typst
  • Use less indentation
    • Typst 0.13.1 produces 4-space indentation, consider 0-space, 1-space or no whitespace at all
    • Going from 4-space to no whitespace saves 5-10% on the tested files.
  • Use less coordinate precision
    • This is a lossy thing that scour does. It's probably not a good fit for Typst (?)

Use Case

It would save some space and bandwidth

Activity

  1. added
    feature request
    on May 31, 2025
  2. MDLC01 commented on May 31, 2025

    @MDLC01
    Collaborator

    At least part of this seems to be covered by #6247

  3. added
    svg
    on May 31, 2025
  4. Enivex commented on May 31, 2025

    @Enivex
    Collaborator

    Point 1: I don't think this is viable due to incremental compilation, but someone correct if I'm wrong.

    Point 2: Using tabs instead of spaces for indentation would save some space without sacrificing human readability.

    Point 3: I suspect this could introduce artifacts.

  5. Dherse commented on Jun 1, 2025

    @Dherse
    Contributor

    @Enivex iirc the IDs were indeed introduced because of incremental compilation (I want to say that they were introduced in one of the gradient PRs but frankly it's been too long). That being said, we might be able to rely on smaller hashes here? and manually detect collisions and do differentiation? That should work, right? Like use a 4-byte hash and then give them an extra byte if you have clashes 🤷‍♂

  6. Enivex commented on Jun 1, 2025

    @Enivex
    Collaborator

    @Enivex iirc the IDs were indeed introduced because of incremental compilation (I want to say that they were introduced in one of the gradient PRs but frankly it's been too long). That being said, we might be able to rely on smaller hashes here? and manually detect collisions and do differentiation? That should work, right? Like use a 4-byte hash and then give them an extra byte if you have clashes 🤷‍♂

    Is file size important enough for this though? For those who truly need minimal svgs there's always external tools like the one mentioned above.

  7. bluss commented on Jun 1, 2025

    @bluss
    ContributorAuthor

    Just punting this to external tools seems fair enough to me. I can see how none of the suggestions really work out, except for indentation.

  8. Enter-tainer commented on Jun 6, 2025

    @Enter-tainer
    Contributor

    whitespace and long id can be well compressed by gzip if one want to serve these svg on web.

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

    feature requestsvg

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions