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

efficient struct packing #264

Merged
merged 4 commits into from
Dec 7, 2021
Merged

efficient struct packing #264

merged 4 commits into from
Dec 7, 2021

Conversation

jkralik
Copy link
Member

@jkralik jkralik commented Dec 5, 2021

No description provided.

@jkralik jkralik force-pushed the jkralik/fix/optimizeMemoryUsage branch from 3121db1 to ce997d8 Compare December 5, 2021 09:30
@codecov-commenter
Copy link

codecov-commenter commented Dec 5, 2021

Codecov Report

Merging #264 (3e819b0) into master (368f19b) will decrease coverage by 0.00%.
The diff coverage is 77.96%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #264      +/-   ##
==========================================
- Coverage   63.79%   63.79%   -0.01%     
==========================================
  Files          79       79              
  Lines        5638     5640       +2     
==========================================
+ Hits         3597     3598       +1     
  Misses       1683     1683              
- Partials      358      359       +1     
Impacted Files Coverage Δ
dtls/client.go 75.22% <0.00%> (ø)
dtls/options.go 46.95% <0.00%> (ø)
dtls/server.go 82.78% <ø> (ø)
message/message.go 0.00% <ø> (ø)
message/option.go 71.12% <0.00%> (ø)
message/pool/message.go 62.76% <0.00%> (ø)
mux/router.go 55.12% <ø> (ø)
net/connUDP.go 61.84% <ø> (ø)
net/monitor/inactivity/inactivitymonitor.go 78.26% <ø> (ø)
net/monitor/inactivity/keepalive.go 91.66% <ø> (ø)
... and 28 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 368f19b...3e819b0. Read the comment docs.

@Danielius1922
Copy link
Member

I still get one report of suboptimal struct size:

$ aligncheck ./...
github.com/plgd-dev/go-coap/v2/message/pool: /home/danielius/go/src/github.com/plgd-dev/go-coap/message/pool/message.go:16:6: struct Message could have size 160 (currently 168)

@sonarcloud
Copy link

sonarcloud bot commented Dec 6, 2021

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

87.8% 87.8% Coverage
4.0% 4.0% Duplication

@@ -11,6 +12,10 @@ func (t Token) String() string {
return hex.EncodeToString(t)
}

func (t Token) Hash() uint64 {
Copy link
Member

Choose a reason for hiding this comment

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

We could cache the value if the function is used often, eg:

type Token struct {
  data []byte
  hash uint64
}

Calculate the value on first use, save it and then use only cached value.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hash is a very cheap operation so was can leave it as is otherwise we need to introduce a constructor which fills the value.

@jkralik jkralik merged commit 9c374b0 into master Dec 7, 2021
@jkralik jkralik deleted the jkralik/fix/optimizeMemoryUsage branch December 7, 2021 13:49
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.

None yet

3 participants