New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proposal: embed: add -embed=compress flag to go #61322
Comments
When are the embedded files decompressed? If compression is signaled by an option like For an embedded |
Agree, this seems hard to impossible to do with Opting into |
I don't think we should have But maybe we could support //go:embed bigfile.bin
func content() string could be a shorthand for something like: //go:embed bigfile.bin
var contentFS embed.FS
var content = sync.OnceValue(func() string {
f, err := content.Open("bigfile.bin")
if err != nil {
panic(err)
}
defer f.Close()
b := new(strings.Builder)
if _, err := io.Copy(b, f); err != nil {
panic(err)
}
return b.String()
}) |
This proposal has been added to the active column of the proposals project |
This sounds a bit premature to me. Unless there is more demand than I realize |
We use Brotli to compress all bundled UI artifacts (HTML, JS, CSS, etc.) with our app. A special HTTP handler either serves those files directly (if the client supports Brotli) or decompresses the bundled Brotli files and serves them uncompressed. The proposal seems to completely ignore this use cases:
I think it's ok to not support all those features upfront, but the proposal in its current form can not be easily extended later. |
This seems too difficult and fraught with problems and there doesn't seem to be much demand for it. |
Based on the discussion above, this proposal seems like a likely decline. |
Ok, sounds good. |
No change in consensus, so declined. |
Sad to see go:embed compression rejected. It would be very useful to reduce binary size by tens of megabytes for a moderately sized web application as well as enable direct streaming of compressed assets to HTTP clients, which is ideal for performance as well. In fact, the lack of compression suport in Any details on the rejection? Are web apps not a priority of golang? |
@silverwind I just looked at Gitea and discovered that you are using Webpack. Therefore you can configure webpack to output gzip compressed files (we do something similar with brotli and vite) and leave the go:embed statements as is. This has several advantages compared to this concrete proposal:
Alternatively if using Webpack isn't a solution for you, I guess one more line in your 1026 line long Makefile to preprocess the files wouldn't hurt either. |
For what it’s worth, I dont really view every potential compression option brought up above as necessary to support. Go is meant to be a simple language: if you want more complication, do it separately. A compress option for embed-able files seems to significantly simplify things for the vast majority of use cases. I just want to check in (and have diffs on) uncompressed large files that have high compressibility.
That said, I have no interest convincing people anymore. People like to bikeshed and argue every use case and angle, and if things aren’t merged then people are satisfied they blocked language “complications”. Those battles just aren’t for me. Cheers.
…On Sat, Sep 9, 2023 at 18:56, Christoph Hack ***@***.***(mailto:On Sat, Sep 9, 2023 at 18:56, Christoph Hack <<a href=)> wrote:
***@***.***(https://github.com/silverwind) I just looked at Gitea and discovered that you are using Webpack. Therefore you can configure webpack to output gzip compressed files (we do something similar with brotli and vite) and leave the go:embed statements as is. This has several advantages compared to this concrete proposal:
- all files are compressed individually, so you can directly serve them using "Content-Encoding: gzip" if supported by the browser (we have written a small http handler to decompress brotli if it's not supported)
- webpack / vite offer many configuration options, like only compressing certain file types and only emitting the compressed file if it's actually smaller than the original (in addition to embedding the file as is and not even generating extra files for certain file sizes)
Alternatively if using Webpack isn't a solution for you, I guess one more line in your 1026 line long Makefile to preprocess the files wouldn't hurt either.
—
Reply to this email directly, [view it on GitHub](#61322 (comment)), or [unsubscribe](https://github.com/notifications/unsubscribe-auth/AAJZIJIEGCD6OUQYZ5TREX3XZSUUDANCNFSM6AAAAAA2H6GSJI).
You are receiving this because you modified the open/close state.Message ID: ***@***.***>
|
I am also in favor of a simple compression option, i just do not like the proposal in it's current state. There are a lot of open questions that need to be answered first.
This comment is not a proposal yet, I am sure there are lot's of other points that need clarification as well. That's just what I meant when I said that the proposal isn't extendable in it's current form. |
The design proposal for embed contains a section on compression to reduce binary size. This has come up for me a few times recently and I wonder if there is any appetite for the final sentence of this section,
"Future work might be to add
-embed=compress
as a go build option for use in limited environments."Having written the same decompression logic a few times now in a few different ways (decompress one file, decompress a tarball, gunzip vs. zstd), it'd be super convenient to have compression of embedded files or dirs built directly into Go.
Another benefit of of allowing compression at the build stage (and on-the-fly decompression once) is for code repositories. Currently, I am checking in a tiny compressed tarball and have tests against the sha256 of the checkin. Tarballs aren't really great for GH repositories, but considering how infrequently this tarball changes, it's an alright tradeoff right now.
This isn't a super pressing need, but I couldn't find a previous open nor closed proposal, and in the original proposal, the only comment that mentions compression is this one (the point of which is that TinyGo rarely targets RAM heavy systems).
The text was updated successfully, but these errors were encountered: