charmbracelet/glamour

Reduce minimum dependency size

Closed this issue · 4 comments

Along the same lines as #124, the github.com/yuin/goldmark-emoji/definition dependency is listed as 14MB by goweight.

I did some tests on a project using glamour:

  • Removing glamour entirely dropped the binary size by 11MB (even though the project didn't use the WithEmoji() option)
  • Replacing glamour with a fork (glamour-slim) that removes goldmark-emoji saved 4MB, which I'm sure would be more if chroma could also be removed
ls -lh bin/
total 228800
-rwxr-xr-x  1 jstall  staff    42M Mar 15 12:16 with-glamour
-rwxr-xr-x  1 jstall  staff    38M Mar 15 12:21 with-glamour-slim
-rwxr-xr-x  1 jstall  staff    31M Mar 15 12:17 without-glamour

At +11MB for the simplest possible usage, glamour adds a lot of bloat to projects. I would love to use glamour if its largest dependencies were optional.

I would love to see these dependencies (especially anything related to emoji) made optional in upstream Glamour. A project of mine that is soon to go public uses Glamour with emoji support disabled, but Glamour is still the vast majority of my binary size.

Given that my project is a CLI app called separately with user arguments for each action, the startup speed is noticeable. Glamour increases the time my project takes to run by several times, even when not using any functionality that uses it (literally displaying my help menu went from instant to a visible terminal refresh).

Removing Glamour makes this behavior go away entirely. I love Glamour and want to continue using it, but in large part thanks to its dependencies, it is ungodly heavy.

Edit: I did some testing and I actually do not see a difference when using a fork without goldmark-emoji. It seems that using a custom renderer without WithEmoji() is correctly avoiding the compiling of the unnecessary code into my binary. My binary bloat seems to be from chroma. Leaving it out saves ~4.5MB and drastically improves my startup time (about a 3.5x speed increase). This is unfortunate, as I happen to like the syntax highlighting, though I guess it is not entirely necessary for what I'm doing.

@caarlos0 This might addressed by yuin/goldmark-emoji#8

yes @justenstall, already merged in the commit: c9a417f

I think we can close this, right?

@caarlos0 yeah this should be resolved now! Thanks!