Skip to content

libct/cg/sd: optimize and test findDeviceGroup#3357

Merged
thaJeztah merged 1 commit intoopencontainers:mainfrom
kolyshkin:more-bytes-less-strings
Apr 27, 2023
Merged

libct/cg/sd: optimize and test findDeviceGroup#3357
thaJeztah merged 1 commit intoopencontainers:mainfrom
kolyshkin:more-bytes-less-strings

Conversation

@kolyshkin
Copy link
Copy Markdown
Contributor

@kolyshkin kolyshkin commented Jan 28, 2022

This includes/depends on #3356, draft until merged.

  1. Using strings.TrimPrefix instead of fmt.Sscanf.

  2. Add a test case and a benchmark.

The benchmark shows some improvement, compared to the old
implementation:

    name               old time/op    new time/op    delta
    FindDeviceGroup-4    39.7µs ± 2%    26.8µs ± 2%  -32.63%  (p=0.008 n=5+5)
    
    name               old alloc/op   new alloc/op   delta
    FindDeviceGroup-4    6.08kB ± 0%    4.23kB ± 0%  -30.39%  (p=0.008 n=5+5)
    
    name               old allocs/op  new allocs/op  delta
    FindDeviceGroup-4       117 ± 0%         6 ± 0%  -94.87%  (p=0.008 n=5+5)

@kolyshkin kolyshkin requested a review from thaJeztah January 28, 2022 03:31
@kolyshkin kolyshkin force-pushed the more-bytes-less-strings branch 2 times, most recently from ddccea2 to 94e14c8 Compare February 1, 2022 02:51
@kolyshkin kolyshkin force-pushed the more-bytes-less-strings branch from 94e14c8 to bdd51d9 Compare February 16, 2022 01:25
@kolyshkin kolyshkin force-pushed the more-bytes-less-strings branch from bdd51d9 to c12d83f Compare March 17, 2022 03:48
@kolyshkin kolyshkin marked this pull request as ready for review March 17, 2022 03:48
@kolyshkin kolyshkin force-pushed the more-bytes-less-strings branch from c12d83f to ed71681 Compare March 17, 2022 03:49
@kolyshkin kolyshkin requested a review from cyphar March 17, 2022 03:50
@kolyshkin
Copy link
Copy Markdown
Contributor Author

Rebased, dropped the commit which contained optimization which did not resulted in any noticeable improvement.

@cyphar @thaJeztah PTAL

thaJeztah
thaJeztah previously approved these changes Mar 17, 2022
Copy link
Copy Markdown
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM

@kolyshkin kolyshkin changed the title More bytes less strings libct/cg/sd: optimize and test findDeviceGroup Mar 17, 2022
@kolyshkin kolyshkin force-pushed the more-bytes-less-strings branch from ed71681 to 63e5028 Compare March 17, 2022 20:04
@kolyshkin
Copy link
Copy Markdown
Contributor Author

@thaJeztah sorry to bother you, I have just updated the commit to remove most of bytes-related ugliness. Apparently, in modern Go versions, using bytes instead of strings does not result in any performance gain (it used to be the case, but appears to be fixed now).

The performance gain (and drastically reduced number of allocations) comes from ditching fmt.Sscanf which is apparently not implemented very well.

The new patch is much smaller and focused, PTAL.

@thaJeztah
Copy link
Copy Markdown
Member

Oh! Interesting that they improved that; good to know!

thaJeztah
thaJeztah previously approved these changes Mar 17, 2022
Copy link
Copy Markdown
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM!!

@kolyshkin kolyshkin requested a review from AkihiroSuda March 21, 2022 18:34
@kolyshkin
Copy link
Copy Markdown
Contributor Author

@AkihiroSuda @cyphar PTAL

@kolyshkin kolyshkin force-pushed the more-bytes-less-strings branch from 63e5028 to ef886e1 Compare March 23, 2022 02:58
@kolyshkin kolyshkin force-pushed the more-bytes-less-strings branch from ef886e1 to d040bf9 Compare March 29, 2022 23:15
@kolyshkin kolyshkin requested a review from thaJeztah March 29, 2022 23:17
@kolyshkin
Copy link
Copy Markdown
Contributor Author

LGTM!!

somehow your LGTM got lost @thaJeztah; PTA(nother)L

@kolyshkin
Copy link
Copy Markdown
Contributor Author

@AkihiroSuda @cyphar @thaJeztah PTAL

@kolyshkin kolyshkin force-pushed the more-bytes-less-strings branch from d040bf9 to 842c131 Compare May 27, 2022 01:16
@kolyshkin kolyshkin added this to the 1.2.0 milestone Jun 9, 2022
@kolyshkin
Copy link
Copy Markdown
Contributor Author

@AkihiroSuda @cyphar @thaJeztah PTAL

@kolyshkin kolyshkin force-pushed the more-bytes-less-strings branch 2 times, most recently from ed02291 to 06f67e9 Compare November 2, 2022 22:01
@kolyshkin kolyshkin force-pushed the more-bytes-less-strings branch from 06f67e9 to 1228258 Compare April 13, 2023 01:09
@kolyshkin
Copy link
Copy Markdown
Contributor Author

@thaJeztah you have previously LGTMed this; PTAAL

1. Use strings.TrimPrefix instead of fmt.Sscanf and simplify the code.

2. Add a test case and a benchmark.

The benchmark shows some improvement, compared to the old
implementation:

name               old time/op    new time/op    delta
FindDeviceGroup-4    39.7µs ± 2%    26.8µs ± 2%  -32.63%  (p=0.008 n=5+5)

name               old alloc/op   new alloc/op   delta
FindDeviceGroup-4    6.08kB ± 0%    4.23kB ± 0%  -30.39%  (p=0.008 n=5+5)

name               old allocs/op  new allocs/op  delta
FindDeviceGroup-4       117 ± 0%         6 ± 0%  -94.87%  (p=0.008 n=5+5)

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
@kolyshkin kolyshkin force-pushed the more-bytes-less-strings branch from a9ed27c to defb1cc Compare April 27, 2023 16:12
@kolyshkin
Copy link
Copy Markdown
Contributor Author

Rebased; @opencontainers/runc-maintainers PTAL

Copy link
Copy Markdown
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM 💙

@thaJeztah thaJeztah merged commit 8af2f48 into opencontainers:main Apr 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants