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

BlockFeeder has quadratic time complexity (O(n^2)) #47

Open
DavidBuchanan314 opened this issue Mar 21, 2022 · 0 comments
Open

BlockFeeder has quadratic time complexity (O(n^2)) #47

DavidBuchanan314 opened this issue Mar 21, 2022 · 0 comments

Comments

@DavidBuchanan314
Copy link

Line 181 slices the front off the buffer, to keep track of what's remaining:

self._buffer = self._buffer[can_consume:]

This operation is O(n), since the python runtime must make a new copy of the data. Since this repeats O(n) times, the overall complexity is O(n^2). This gets particularly noticeable for larger inputs (>1MB).

I suggest either using an io.BytesIO object, or simply keeping track of an index into the buffer.

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

No branches or pull requests

1 participant