-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Feat/add server side compression support #3456
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
base: dev
Are you sure you want to change the base?
Feat/add server side compression support #3456
Conversation
…arg in the callback method and function
…case, the should_compress function will return true without a jsondumps check
…in the app.CallBack decorator
|
@caue-paiva thanks very much for the PR - I'll ask @T4rk1n to look it over when he gets a chance, but it may be a week or more before he can make time to evaluate it. |
|
Hello, could any of the reviewers take a look at this? I think the visual test is flaky |
Yes the percy tests are flaky, no worry as long as the tests pass it's really just to look at them if it's expected some change from the frontend code. |
|
Hi guys, i am counting on this PR for an university project (that involves open-source contributions), could we get some reviews going? |
|
Hello @caue-paiva, I am just a fellow contributor here, but I think that this makes a dcc.Store unusable on the clientside, as you'd have to decompress the data. I have an open feature request / PR sorta (#3471) that allows for intercepting the data on the server side and replacing it with server side stores of variables. I feel that this would solve the issue that you are trying to handle. As far as larger payloads, it could be better to compress the entire payload from the client with a header, and compressing the whole body to go to the server. Just my thoughts on the matter. 🙂 |
T4rk1n
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the proposed api with the explicit callback argument might not the best approach for this.
The compression_manager could be an optional argument of dash.Dash instead and provide a default based on installed lib:
- if brotli is installed take that.
- next default to gzip
- can be set to None to disable compression.
If we go the default route with gzip, we'd have to also disable the compression if the dcc.Store is used in a clientside callback.
The compression should also be defined at the component level, I think a prop system like the persistence we have in the defaultProps
Example for the store:
Store.propTypes = {
...
compression: PropTypes.boolean,
compressed_props: PropTypes.arrayOf(PropTypes.oneOf(['data']),
compression_type: PropTypes.oneOf(['gzip', 'zlib', 'brotli'])
}
Store.defaultProps = {
...,
compressed_props: ['data'],
}This way the compression could be used in other props like for dataframes and the component can handle the compression on the client too if required.
For motivation see the following issue: #3452
Solution Overview: Server-Side Compression
This implementation provides a server-side only compression solution for dcc.Store components. The compression and decompression occur entirely on the server during callback execution, with the following key characteristics:
Important Note: This is explicitly a server-side solution. The client-side JavaScript cannot access or manipulate the compressed data - it only receives the final decompressed JSON payload.
Implementation Details
New Components Added
get_compression_manager_from_kwargs()for parameter extractionCore Functionality
Integration with Callback System
The compression manager integrates seamlessly into the existing callback architecture:
CompressionManagerparameter to callback decoratorsUsage Example
Summary
This feature provides a server-side compression solution for dcc.Store components that:
The implementation successfully addresses the performance bottlenecks identified in the original issue while maintaining the simplicity and reliability expected from the Dash framework.
Contributor Checklist
optionals
CHANGELOG.md