Skip to content

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

@DavidBuchanan314

Description

@DavidBuchanan314

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions