fbchat-dev / fbchat

Facebook Chat (Messenger) for Python
https://fbchat.readthedocs.io
BSD 3-Clause "New" or "Revised" License
1.19k stars 412 forks source link

Regular expression is slow in get_json #48

Closed dstelzer closed 7 years ago

dstelzer commented 8 years ago

There's a noticeable delay in each call to get_json. Since the cruft at the beginning is always the same, why not use a slice operation instead of a regex?

madsmtm commented 7 years ago

To make get_json work for as long as possible. Maybe one day Facebook decides to remove the for (;;);. And then everybody who's not using the latest version of fbchat, will get screwed over ;)

Schmavery commented 7 years ago

Would it be faster to do something like

i = text.index("{")
if i > -1: return text[i:]
else: return ""

I'd imagine it would have the same behaviour if so.

madsmtm commented 7 years ago

Try testing it's speed, and if it is indeed faster, then make a pull request

madsmtm commented 7 years ago

I did the speed test, and included your code in a commit somewhere ;)