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

optimise yarahunter #89

Merged
merged 4 commits into from
Jun 24, 2024
Merged

optimise yarahunter #89

merged 4 commits into from
Jun 24, 2024

Conversation

ibreakthecloud
Copy link
Member

@ibreakthecloud ibreakthecloud commented Jun 21, 2024

  • Using string.Join on million of record is really slow. Using Map here were reads and writes are in o(1)
  • using fmt writes the error log to stdout, that then goes to json. which we don't want.

// todo

  • size of output(result) json can grow depending on stringsMatch, need fix for that
  • size of map will increase the in-mem usage, need to fix this

using fmt writes the error log to stdout, that then goes to json. which we don't want.
@ibreakthecloud ibreakthecloud changed the title donot use strings.Join optimise yarahunter Jun 21, 2024
@ibreakthecloud
Copy link
Member Author

ibreakthecloud commented Jun 21, 2024

This changes were benchmarked by @ramanan-ravi @ibreakthecloud @gnmahanth @noboruma @akumars1 on different setups

Username Now Before
@ramanan-ravi 9m30s > 30m
@ibreakthecloud 30m ~1 day
@noboruma < 30m > 30m
@akumars1 14m infinite
@gnmahanth 5m > 30m

cc: @shyam-dev

pkg/scan/process_image.go Outdated Show resolved Hide resolved
pkg/scan/process_image.go Outdated Show resolved Hide resolved
@ibreakthecloud ibreakthecloud marked this pull request as ready for review June 23, 2024 09:05
@ibreakthecloud ibreakthecloud merged commit 3fea260 into main Jun 24, 2024
1 check passed
@ibreakthecloud ibreakthecloud deleted the ibreakthecloud-patch-1 branch June 24, 2024 05:06
@@ -211,6 +212,10 @@ func isExecutable(path string) bool {
return fileMimetypeCheck(path, execMimeTypes)
}

func BytesToString(b []byte) (s string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

There is a reason golang calls this library unsafe !! Is there a reason we prefer this over string() or fmt.Sprintf ? @noboruma / @ibreakthecloud ??

Copy link
Member Author

@ibreakthecloud ibreakthecloud Jun 24, 2024

Choose a reason for hiding this comment

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

unsafe.String is faster than using string(), since unsafe doesnot actually copies the data but instead creates a new string header that references the same underlying data as the byte slice. The down-side of this is any changes in byte slice will result in affecting the string, which is shouldn't be any trouble in our case.
cc: @noboruma

also I think we should use -d=checkptr flag while building if we're not already

Copy link
Member Author

Choose a reason for hiding this comment

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

one thing I am not sure if garbage collector will free this prematurely. @noboruma

Copy link
Contributor

Choose a reason for hiding this comment

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

There are cases where GC can prematurely release the memory, but not in that scenario because the reference we have created is not unsafe anymore, it's a regular string and this will prevent GC from collecting further

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.

5 participants