Open pcordes opened 1 year ago
Some of the challenges when it comes to full urls, are:
I'm sure there are other and better ways to compress and encode url's, but these are the tricky bits to take into account
Thanks both: agreed it would be nicer to have more compact "full" URLs. I'm sure we can do better, but @partouf covers a lot of the bases. Interestingly, for another project I have started using CompressionStream which might offer the right amount of support for our uses.
Thanks both: agreed it would be nicer to have more compact "full" URLs. I'm sure we can do better, but @partouf covers a lot of the bases. Interestingly, for another project I have started using CompressionStream which might offer the right amount of support for our uses.
Right, I looked at that, but the Firefox version support starts at 113, isn't that a quite recent version?
Oh! You're not wrong actually. That seems too recent; so we'll have to find something else.
https://github.com/OneIdentity/zstd-js looks promising. also our base64 stuff is using the =
and other chars that aren't safe for URIs...so we can probably switch to one that uses -
and _
or whatever... worth a look!
So is the size not LZ-string's fault, but rather the post-processing of its output, and all the config info that gets concatenated with the source code? Like base64 and then replace some single characters with 3 characters, defeating some of the compression?
If LZ-string is using DEFLATE (aka gzip aka LZ77) with an encoder that's even half-way reasonable in terms of actually finding redundancy, dropping in another compression library won't fix the problem.
But if it's making a valid DEFLATE stream while not actually finding nearly as much redundancy as command-line gzip -1
/ zlib, then that's a problem, and yeah a different library could do better. (I'd assume it's a challenge to write an efficient compressor in JS, since I think you'd want unaligned byte access for more efficiently checking for matches in the compression dictionary in chunks of 4 bytes or something. Lossless compression is a CPU time vs. compression ratio problem, with better-optimized algorithms giving a better tradeoff. Is there a tuning knob, or did LZ-string just sacrifice a lot of efficiency for ease of implementation and/or speed?)
(Also doing character substitutions on the base64 string to map to a URI-safe character set without %xx expansions for URL-encoding is a very good idea.)
Is your feature request related to a problem? Please describe
According to https://github.com/compiler-explorer/compiler-explorer/issues/597 , we do use LZ-string to compress long URLs. But it seems to do a much worse job than DEFLATE (gzip) or ZSTD.
A 10.1K C file with two version of a function (with large chunks of similar text) produces an 8KiB base64 URL (8775 bytes). Or 8125 byte if I close one of the compiler panes.
But locally doing
gzip | base64
makes only a 3.87K base64 string (3972 bytes) from a 2.87K.gz
file. (Or somewhat larger from azstd
-compressed file, 4.1KiB base64 from 3.03K binary.) Even usinggzip -1 | base64
instead of the default-6
only makes a 4.4K base64.So why isn't compiler-explorer making shorter URLs that shrink redundant source? I know it has to include some configuration text, not just the source, but I assume that doesn't account for an extra 4KiB after compression.
Describe the solution you'd like
A good compression algorithm should find the redundancy between large chunks of similar code, so URL size is correlated more with the information content of the linked code, not its byte-count in ASCII. ZSTD is fast and good.
DEFLATE aka LZ77 (gzip) is very widely available and compresses slightly better in the one case I just tested, although it's slower. Not a huge deal for code that's in the tens of KiB size range.
Describe alternatives you've considered
Maybe there's some LZ-string tuning or compression-level option where the current setting is bad?
IDK why LZ-string isn't already compressing like gzip locally; I assumed from the name that's what it would do. Perhaps this should be treated as a bug report instead of a feature request? But if it needs a re-arrangement of the order of serialization / compression / base64, it might need a new URL format version number, which sounds like a feature to me.
I tried
base64 -d
to decode the part of the URL after the:
, but it says invalid input after writing 583 bytes of binary data.Additional context
The source I was editing was for https://stackoverflow.com/questions/77037432/suggestions-on-further-optimising-this-chi-square-function-using-sse2-intrinsics (where I had to trim my answer down to keep it less than 30K characters; it was initially over 34K.)
The actual link is
https://godbolt.org/#z:OYLghAFBqd5QCxAYwPYBMCmBRdBLAF1QCcAaPECAMzwBtMA7AQwFtMQByARg9KtQYEAysib0QXACx8BBAKoBnTAAUAHpwAMvAFYTStJg1AB9U8lJL6yAngGVG6AMKpaAVxYM9DgDJ4GmADl3ACNMYgkuAGZSAAdUBUJbBmc3Dz04hJsBX38gllDwriiLTCsshiECJmICFPdPLhKypMrqghzAkLCI6IUqmrq0xr62jryCnoBKC1RXYmR2DgBSACZIv2Q3LABqJcjHPvxBADoEPewljQBBS6v0WeD6beBMAmQEPAUAR1dqzHRjExXEQAG6YZAQPwEbYJABemFI21cUIAHMZoQAqdBMKqTW5LADsACFbtsydsAPQU7ZMBRKGoQOGYXaRbDbDR4yIk66k8lU7YAFQA8gARIUgbZ4KgwvDwlkXSIi7YANgArKrIsrEa4lEioZEVujtmhXII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