Opened 6 years ago

Closed 6 years ago

#13821 closed enhancement (implemented)

Various optimisations to Stem

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


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 6 years ago by atagar

Resolution: implemented
Status: newclosed

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)

... or...

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

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.