python-overpy icon indicating copy to clipboard operation
python-overpy copied to clipboard

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

Open kavigupta opened this issue 2 years ago • 0 comments

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

kavigupta avatar Aug 25 '23 20:08 kavigupta