Skip to content

Make StyledStrings a normal package again #57998

@KristofferC

Description

@KristofferC

StyledStrings makes writing colored text more convenient, but its design incurs significant latency for nearly all Julia users. This is partly due to its type piracy (as reported in JuliaLang/StyledStrings.jl#61) and untyped internal fields. I have debugged countless latency issues, and it is quite common that the root cause ends up being simply that StyledStrings get loaded (which now happens when just opening the REPL) and due to its type piracy invalidates many chunks of precompiled code. For instance, see this discussion, where the first call to Pkg.add becomes three times slower solely because StyledStrings is loaded. Similar issues have also impacted Julia's parallel precompilation, as detailed here.

Latency is arguably one of the biggest concerns in Julia, so any regressions must be taken very seriously. In the #ttfx Slack channel, many users mentioned that they continue using Julia v1.10 because of its generally better latency. Perhaps coincidentally, StyledStrings was added in version 1.11. The type piracy issue was reported a year ago, and there have been attempts (by contributors other than the original author) to work around it, the latest being this pull request. However, these feel to me like trying to plaster a fix on something that is quite fundamentally broken.

There has also been talk about using StyledStrings more extensively to render stacktraces and error messages etc. However, due to the untyped fields and dynamic dispatch this seems quite scary with the new interest in trimming to produce small binaries. AFAIU, the very dynamic design of StyledStrings makes them hard to support together with trimming.

My patience with debugging these latency issues has run out. I keep encountering the same problems repeatedly, and it is no longer fun. The benefit of having syntax highlighting in markdown is, in my opinion, vastly outweighed by the cost of imposing extra latency on all Julia users to the point that they may hesitate to upgrade to newer Julia versions. Therefore, I argue that it is time to remove the (documented as experimental) StyledStrings from being a standard library and treat it as a normal package. This change could even improve the latency for packages that depend on StyledStrings, as the AnnotatedX types and AnnotatedIOBuffer would then reside solely within the StyledStrings package, eliminating type piracy.

This was a worthwhile experiment, but it ultimately did not pan out, and it would be unfortunate to remain stuck in a bad situation indefinitely.

Metadata

Metadata

Assignees

No one assigned

    Labels

    excisionRemoval of code from Base or the repositorylatencyLatency

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions