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

data/binding: optimized convertion using strconv #2142

Merged
merged 3 commits into from
Apr 14, 2021

Conversation

Jacalz
Copy link
Member

@Jacalz Jacalz commented Apr 6, 2021

Description:

This updates the data bindings to use the strconv package instead of fmt for conversions, leading to improved performance (benchmarks to come). This is currently WIP and is just a proof of concept with generations scripts yet to have been updated to take this into effect.

Fixes #1735

Checklist:

  • Tests included.
  • Lint and formatter run with no errors.
  • Tests all pass.

@andydotxyz
Copy link
Member

Looks like a good change thanks.
I wonder (random thought) should we also use this version when someone manually specifies the default format?

@Jacalz
Copy link
Member Author

Jacalz commented Apr 9, 2021

Here are the results of the benchmarks for this change. The benchmarks are adaptations of the corresponding tests with asserts removed. The metric are thus results of 4 .Get() and 3 .Set() calls being made on the underlying types.

name             old time/op    new time/op    delta
BoolToString-8     11.9µs ± 1%     5.7µs ± 2%  -52.02%  (p=0.008 n=5+5)
FloatToString-8    14.6µs ± 1%     7.6µs ± 0%  -47.85%  (p=0.016 n=5+4)
IntToString-8      12.3µs ± 0%     6.1µs ± 1%  -50.52%  (p=0.008 n=5+5)
StringToBool-8     13.5µs ± 2%     7.6µs ± 0%  -43.77%  (p=0.016 n=5+4)
StringToFloat-8    15.4µs ± 1%     8.8µs ± 0%  -42.63%  (p=0.008 n=5+5)
StringToInt-8      14.1µs ± 1%     7.6µs ± 0%  -46.01%  (p=0.008 n=5+5)

name             old alloc/op   new alloc/op   delta
BoolToString-8       486B ± 0%      377B ± 0%  -22.43%  (p=0.008 n=5+5)
FloatToString-8      575B ± 0%      462B ± 0%  -19.65%  (p=0.008 n=5+5)
IntToString-8        511B ± 0%      398B ± 0%  -22.11%  (p=0.008 n=5+5)
StringToBool-8       551B ± 0%      447B ± 0%  -18.82%  (p=0.008 n=5+5)
StringToFloat-8      622B ± 0%      493B ± 0%  -20.79%  (p=0.008 n=5+5)
StringToInt-8        575B ± 0%      461B ± 0%  -19.77%  (p=0.008 n=5+5)

name             old allocs/op  new allocs/op  delta
BoolToString-8       19.0 ± 0%      13.0 ± 0%  -31.58%  (p=0.008 n=5+5)
FloatToString-8      22.0 ± 0%      17.0 ± 0%  -22.73%  (p=0.008 n=5+5)
IntToString-8        18.0 ± 0%      13.0 ± 0%  -27.78%  (p=0.008 n=5+5)
StringToBool-8       20.0 ± 0%      15.0 ± 0%  -25.00%  (p=0.008 n=5+5)
StringToFloat-8      22.0 ± 0%      17.0 ± 0%  -22.73%  (p=0.008 n=5+5)
StringToInt-8        20.0 ± 0%      15.0 ± 0%  -25.00%  (p=0.008 n=5+5)

In summary, conversions are about twice as fast, we are allocating about 20% less each time. I'd say that it is a pretty good improvement 🙂

Copy link
Member Author

@Jacalz Jacalz left a comment

Choose a reason for hiding this comment

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

I was unsure if I should leave my quick and dirt benchmarks in or not. They are there now, but I can easily remove them if we think that's a better idea.

@Jacalz Jacalz marked this pull request as ready for review April 10, 2021 16:23
@Jacalz Jacalz merged commit f9769d6 into fyne-io:develop Apr 14, 2021
@Jacalz Jacalz deleted the binding-strconv branch April 14, 2021 19:15
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.

2 participants