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

simplify urlopen reading code. make the runtime linear rather than quadratic #111

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kavigupta
Copy link

Issue type
  • Bugfix

The code hangs when accessing a large query (e.g., all parks in California). This is because the code as written repeatedly adds to a string in a loop. This is (1) not necessary, since you can just run f.read() and (2) unnecessarily slow, as it requires reallocation and copying of the entire string. See, e.g., this amazon style guide for more details.

Summary

I replaced a block of code

            response = f.read(self.read_chunk_size)
            while True:
                data = f.read(self.read_chunk_size)
                if len(data) == 0:
                    break
                response = response + data

with the line

response = f.read()

This is equivalent

Frankkkkk added a commit to Frankkkkk/python-overpy that referenced this pull request May 6, 2024
There is no need to support chunks in python3 as the `read()` interface
does that for us. Furthermore, this improves fetch performance in large
queries (c.f. DinoTools#111).

Signed-off-by: Frank Villaro-Dixon <[email protected]>
Frankkkkk added a commit to Frankkkkk/python-overpy that referenced this pull request May 7, 2024
There is no need to support chunks in python3 as the `read()` interface
does that for us. Furthermore, this improves fetch performance in large
queries (c.f. DinoTools#111).

Signed-off-by: Frank Villaro-Dixon <[email protected]>
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.

1 participant