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

Improve serializing #313

Merged
merged 2 commits into from
Apr 16, 2023
Merged

Improve serializing #313

merged 2 commits into from
Apr 16, 2023

Conversation

Ogeon
Copy link
Owner

@Ogeon Ogeon commented Apr 16, 2023

This fixes a long-standing bug in how Alpha and PreAlpha are serialized. They used to be flattened to a map, which is fine in JSON but not in more expressive formats, such as RON. The replacement implementation will only handle a subset of possible values (structs, tuples and sequences), but they should be the most common ones. It should also be possible to extend it later.

I have also taken the opportunity to add some helpful utility functions for serializing and de-serializing.

Closed Issues

Breaking Change

Technically breaking, since it changes the serialization format a bit, but the old behavior was buggy and not always usable. The serialized type and name for Alpha and PreAlpha is now inherited from the color's type. So, for example, Srgba will be serialized and de-serialized as an Rgb struct with an additional alpha field. Unit types get extended to newtypes, and newtypes get extended to tuples.

@Ogeon
Copy link
Owner Author

Ogeon commented Apr 16, 2023

bors r+

@github-actions
Copy link

Benchmark for ecd70f8

Click to view benchmark
Test Base PR %
Cie family/lab to lch 3.0±0.02µs 3.1±0.02µs +3.33%
Cie family/lab to xyz 764.1±3.96ns 764.3±3.40ns +0.03%
Cie family/lch to lab 2.4±0.01µs 2.4±0.02µs 0.00%
Cie family/linsrgb to xyz 285.2±1.48ns 291.8±2.50ns +2.31%
Cie family/linsrgb to xyz - wide::f32x8 103.5±0.45ns 103.3±0.54ns -0.19%
Cie family/xyz to lab 21.1±0.18µs 21.2±0.73µs +0.47%
Cie family/xyz to yxy 662.1±2.92ns 655.5±3.39ns -1.00%
Cie family/yxy to xyz 525.5±1.63ns 534.2±5.89ns +1.66%
Matrix functions/matrix_inverse 11.5±0.11ns 11.7±0.05ns +1.74%
Matrix functions/multiply_3x3 10.5±0.05ns 10.4±0.04ns -0.95%
Matrix functions/multiply_rgb_to_xyz 6.4±0.05ns 6.4±0.10ns 0.00%
Matrix functions/multiply_xyz 6.4±0.01ns 6.4±0.03ns 0.00%
Matrix functions/multiply_xyz_to_rgb 6.4±0.04ns 6.4±0.03ns 0.00%
Matrix functions/rgb_to_xyz_matrix 30.1±0.13ns 30.1±0.12ns 0.00%
Rgb family/hsl to hsv 643.5±6.26ns 640.4±6.32ns -0.48%
Rgb family/hsl to linear hsl 12.1±0.06µs 12.3±0.10µs +1.65%
Rgb family/hsl to rgb 1989.9±8.40ns 1991.0±9.66ns +0.06%
Rgb family/hsv to hsl 848.9±12.77ns 817.9±11.04ns -3.65%
Rgb family/hsv to hwb 223.0±0.83ns 222.7±0.97ns -0.13%
Rgb family/hsv to linear hsv 10.7±0.04µs 11.3±0.05µs +5.61%
Rgb family/hsv to rgb 1853.0±10.65ns 1917.4±19.35ns +3.48%
Rgb family/hwb to hsv 464.5±3.81ns 498.3±6.42ns +7.28%
Rgb family/hwb to linear hwb 11.3±0.05µs 11.9±0.06µs +5.31%
Rgb family/linear hsl to hsl 10.7±0.05µs 10.7±0.07µs 0.00%
Rgb family/linear hsv to hsv 10.1±0.05µs 10.2±0.05µs +0.99%
Rgb family/linear hwb to hwb 10.8±0.08µs 11.0±0.08µs +1.85%
Rgb family/linsrgb to rgb 5.5±0.03µs 5.5±0.12µs 0.00%
Rgb family/linsrgb to rgb - wide::f32x8 5.4±0.03µs 5.4±0.03µs 0.00%
Rgb family/linsrgb_f32 to rgb_u8 906.2±3.75ns 908.0±3.48ns +0.20%
Rgb family/linsrgb_f64 to rgb_u8 1170.3±4.99ns 1169.3±5.12ns -0.09%
Rgb family/rgb to hsl 801.0±7.21ns 801.0±4.80ns 0.00%
Rgb family/rgb to hsl - wide::f32x8 497.5±2.23ns 497.8±2.18ns +0.06%
Rgb family/rgb to hsv 498.1±1.89ns 498.4±2.18ns +0.06%
Rgb family/rgb to hsv - wide::f32x8 439.6±1.82ns 435.4±1.78ns -0.96%
Rgb family/rgb to linsrgb 7.5±0.09µs 8.0±0.04µs +6.67%
Rgb family/rgb to linsrgb - wide::f32x8 3.7±0.02µs 3.7±0.01µs 0.00%
Rgb family/rgb_u8 to linsrgb_f32 331.8±1.43ns 332.5±1.45ns +0.21%
Rgb family/rgb_u8 to linsrgb_f64 331.5±1.09ns 331.5±1.58ns 0.00%
Rgb family/xyz to linsrgb 337.7±1.36ns 339.8±1.35ns +0.62%
Rgb family/xyz to linsrgb - wide::f32x8 103.8±0.41ns 102.8±0.68ns -0.96%

@bors
Copy link
Contributor

bors bot commented Apr 16, 2023

Build succeeded:

@bors bors bot merged commit fe7e57e into master Apr 16, 2023
@bors bors bot deleted the improve_serializing branch April 16, 2023 13:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Serialization not compatible with many formats because of flatten
1 participant