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

Save 8 bytes per runner.Result allocation #588

Merged
merged 1 commit into from
Apr 20, 2022

Conversation

jimen0
Copy link
Contributor

@jimen0 jimen0 commented Apr 18, 2022

TL;DR: runner.Result wasn't aligned in an optimal way leading to 8 bytes being wasted per object. Since it stores results, I believe this is an easy win that makes httpx a little bit less resource-intensive when working on large jobs.

$ fieldalignment github.com/projectdiscovery/httpx/runner       
[REDACTED]/httpx/runner/runner.go:1437:13: struct of size 600 could be 592

Below you'll find the struct layout before and after. Padding (wasted, unused bytes) is seen in red color.

  • Old struct

    result-unoptimized

  • Optimized struct

    result-optimized

fieldalignment is an official Go tool.

@jimen0
Copy link
Contributor Author

jimen0 commented Apr 18, 2022

FYI @ehsandeep - Please, let me know your thoughts on this! This is just the struct layout change + gofmt -w -s.

@ehsandeep ehsandeep requested a review from Mzack9999 April 18, 2022 12:29
@ehsandeep ehsandeep merged commit c374610 into projectdiscovery:dev Apr 20, 2022
@jimen0 jimen0 deleted the result-shrink branch April 20, 2022 21:18
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.

3 participants