Opened 3 years ago

Closed 3 years ago

#13821 closed enhancement (implemented)

Various optimisations to Stem

Reported by: oherrala Owned by: atagar
Priority: Medium Milestone:
Component: Core Tor/Stem Version:
Severity: Keywords:
Cc: Actual Points:
Parent ID: Points:
Reviewer: Sponsor:

Description

Various optimisations to stem to make stem.descriptor.parse_file() faster.

Individual patches attached.

Things learned from doing this:

  • cProfile and line_profiler are cool tools used together.
  • One should compile regexp outside of functions and loops.
  • isinstanceof() is slow. Maybe trust later functions to do the right thing(TM) and catch exception when type is wrong
  • Boringly Python's datetime.datetime.strptime() is slow. Replaced with regexp.

Child Tickets

Change History (6)

comment:1 Changed 3 years ago by atagar

  • Resolution set to implemented
  • Status changed from new to closed

Fantastic, thanks! Pushed with some minor tweaks. I'm surprised and a tad sad isinstance() isn't more performant. It should be a simple comparison of the class attribute...

>>> def my_isinstance(v, c):
...   return type(v) == c
... 
>>> my_isinstance('hello', str)
True

... or...

>>> def my_isinstance(v, c):
...   return v.__class__ == c
... 
>>> my_isinstance('hello', str)
True

It made for slightly friendlier code. Are you sure dropping isinstance() had a substantial impact?

If it did then there's a few other isinstance() calls in str_tools.

Note: See TracTickets for help on using tickets.