Skip to content
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

[zstd] pass level param through to compress/zstd encoder #2045

Merged
merged 2 commits into from
Oct 15, 2021

Conversation

lizthegrey
Copy link
Contributor

I'm also open to explicitly enumerating the encoder categories as was done with gzip, but decided to do the sync.Map approach instead for simplicity in case the number range changes meaning down the road and we need more or fewer numbers, etc.

https://pkg.go.dev/sync#Map says it's okay to use it as it fits (1) the entry for a given key is only ever written once but read many times, as in caches that only grow

@ghost ghost added the cla-needed label Sep 30, 2021
@lizthegrey lizthegrey closed this Oct 1, 2021
@lizthegrey lizthegrey reopened this Oct 1, 2021
@lizthegrey
Copy link
Contributor Author

lizthegrey commented Oct 1, 2021

closing/reopening to possibly get CLA status to refresh? there we go.

@ghost ghost removed the cla-needed label Oct 1, 2021
@bai bai requested a review from dnwe October 4, 2021 02:39
@dnwe
Copy link
Collaborator

dnwe commented Oct 13, 2021

@lizthegrey thanks for these changes, I'm happy to approve as I think we should be exposing the level

FWIW we previously had a PR from someone (#1869) suggesting that sync.Once locking was somehow expensive and that's why the setup had been moved to func init(), but we probably should have pressed for more benchmark evidence at that time because it seems like it would only ever have effected startup time and wasn't worth optimising for.

Aside, whilst it doesn't strictly need it at the moment (because we're not exposing any options), could you mirror the use of a sync.Map in the decode case too so that the decoder is only initialised on-demand in a similar way? I know people have been interesting in customising the encoder and decoder so I think this would be a good step toward exposing more options going forward.

@lizthegrey
Copy link
Contributor Author

Aside, whilst it doesn't strictly need it at the moment (because we're not exposing any options), could you mirror the use of a sync.Map in the decode case too so that the decoder is only initialised on-demand in a similar way? I know people have been interesting in customising the encoder and decoder so I think this would be a good step toward exposing more options going forward.

Do you prefer use of a Pool or of a single returned zstd.Reader? I worry there's no meaningful map key to use, so might the Pool be a better construct to use here?

@lizthegrey
Copy link
Contributor Author

Aside, whilst it doesn't strictly need it at the moment (because we're not exposing any options), could you mirror the use of a sync.Map in the decode case too so that the decoder is only initialised on-demand in a similar way? I know people have been interesting in customising the encoder and decoder so I think this would be a good step toward exposing more options going forward.

Do you prefer use of a Pool or of a single returned zstd.Reader? I worry there's no meaningful map key to use, so might the Pool be a better construct to use here?

Or we could create a CompressionOptions{} struct that could be used as the map key I suppose. still leaves open why the other mechanisms use a Pool but zstd does not.

@dnwe
Copy link
Collaborator

dnwe commented Oct 13, 2021

@lizthegrey historically this was due to the use of the klaus/compress library for zstd which differs from compress/gzip and /pierrec/lz4, because it manages its own sync.Pool of encoders/decoders and spawns goroutines when you invoke it (see compress#264 for some of the old context)

@lizthegrey
Copy link
Contributor Author

lizthegrey commented Oct 15, 2021

@lizthegrey thanks for these changes, I'm happy to approve as I think we should be exposing the level

FWIW we previously had a PR from someone (#1869) suggesting that sync.Once locking was somehow expensive and that's why the setup had been moved to func init(), but we probably should have pressed for more benchmark evidence at that time because it seems like it would only ever have effected startup time and wasn't worth optimising for.

Aside, whilst it doesn't strictly need it at the moment (because we're not exposing any options), could you mirror the use of a sync.Map in the decode case too so that the decoder is only initialised on-demand in a similar way? I know people have been interesting in customising the encoder and decoder so I think this would be a good step toward exposing more options going forward.

Done, there's now both ZstdDecoderParams and ZstdEncoderParams and lazy-creation when a decoder or encoder is requested with a new set of parameters.

@lizthegrey lizthegrey requested a review from bai October 15, 2021 03:39
Copy link
Collaborator

@dnwe dnwe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants