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

Optimize random string generation #403

Merged
merged 1 commit into from
Sep 6, 2022

Conversation

anuraaga
Copy link
Contributor

@anuraaga anuraaga commented Sep 6, 2022

Currently, random string generation uses cryptographic random which is very slow. Random strings are used for identifiers and don't seem to have any cryptographic significance (please confirm!) so this removes that, and also applies some smaller optimizations.

It stood out in profiles within non-alloc, unfortunately the numbers are still quite dominated by allocator / GC so reducing garbage will be an ongoing effort.

After

Preparing CRS...
CRS PATH: /var/folders/vx/38td0k79201f9zn_myzbqx_40000gn/T/crs1403234494
goos: darwin
goarch: arm64
pkg: github.com/corazawaf/coraza/v3/testing
BenchmarkCRSSimplePOST
BenchmarkCRSSimplePOST-10    	     541	   2162702 ns/op
PASS

Before

Preparing CRS...
CRS PATH: /var/folders/vx/38td0k79201f9zn_myzbqx_40000gn/T/crs2813219423
goos: darwin
goarch: arm64
pkg: github.com/corazawaf/coraza/v3/testing
BenchmarkCRSSimplePOST
BenchmarkCRSSimplePOST-10    	     548	   2295711 ns/op
PASS

Copy link
Member

@jptosso jptosso left a comment

Choose a reason for hiding this comment

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

LGTM

@jptosso jptosso merged commit b1d1bb4 into corazawaf:v3/dev Sep 6, 2022
@fzipi
Copy link
Member

fzipi commented Sep 6, 2022

@anuraaga Well...bad naming.

This should be called pseudo random, not random string. As an internally exported method, if I want to call it then I'll be surprised not to have a real random string. Can we rename this to PseudoRandom?

@jptosso
Copy link
Member

jptosso commented Sep 6, 2022

Keep in mind this is in internals, and this is not exported. Maybe a comment would be enough, we assume there are no random strings

@jcchavezs
Copy link
Member

We can change it post merge.

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.

4 participants