Skip to content

Performance: read the response dump line by line instead of loading the whole thing in memory#5

Merged
philnash merged 4 commits intophilnash:masterfrom
kpumuk:dmytro/streamed
Mar 12, 2018
Merged

Performance: read the response dump line by line instead of loading the whole thing in memory#5
philnash merged 4 commits intophilnash:masterfrom
kpumuk:dmytro/streamed

Conversation

@kpumuk
Copy link
Copy Markdown
Contributor

@kpumuk kpumuk commented Mar 7, 2018

The response from the service will grow over time. There is no way to get passwords unpwned, so we can safely assume the list will keep growing, adding more new hashes. One day it will grow large enough to start taking down servers when users "DDoS" applications with known "big" pwned password hash prefixes.

This PR switches from "load everything to memory and find our hash" to "fetch data in chunks, and process line by line".

Regular expressions removal

In Ruby start_with? is heavily optimized compared to regular expressions (more than 2 times faster). This PR replaces regular expressions with start_with?

Before: (1000 requests for "password" with mocked network calls)

 13.103359   0.734251  13.837610 ( 14.620959)
 13.238428   0.742140  13.980568 ( 14.506166)

After: (1000 requests for "password" with mocked network calls)

 12.836573   0.729563  13.566136 ( 14.191792)
 12.408245   0.642944  13.051189 ( 13.333299)

P.S. Usually I hate micro-optimizations of this sort, but I was bored, and it does not really decrease readability of the code, so why not

Dmytro Shteflyuk added 4 commits March 7, 2018 02:34
…he whole thing in memory

The response from the service will grow over time. There is no way to get passwords [unpwned](danielmiessler/SecLists#155), so we can safely assume the list will keep growing, adding more an more new hashes. One day it will grow large enough to start taking down servers, when users "DDoS" applications with known "big" pwned password hash prefixes.

This PR switches from "load everything to memory and find our hash" to "fetch data in chunks, and process line by line".
In Ruby `start_with?` is heavily optimized compared to regular expressions (more than 2 times faster). This PR replaces regular expressions with `start_with?`

```
 13.103359   0.734251  13.837610 ( 14.620959)
 13.238428   0.742140  13.980568 ( 14.506166)
 12.836573   0.729563  13.566136 ( 14.191792)
 12.408245   0.642944  13.051189 ( 13.333299)
```

P.S. Usually I hate micro-optimizations of this sort, but I was bored, and it does not really decrease readability of the code, so why not
@philnash philnash merged commit 0e385f8 into philnash:master Mar 12, 2018
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.

2 participants