optimize runtime
A `RatingRow`'s `id` and `updated` are never used, but creating them a million+ times is quite expensive, so initializing them with `None` saves a lot of time. `dataclasses`' `fields` function is also quite expensive; loading the fields from a row directly saves a lot of CPU cycles.
This commit is contained in:
parent
1038b4eaff
commit
9f6baa99b0
1 changed files with 3 additions and 1 deletions
|
|
@ -83,7 +83,7 @@ class RatingRow:
|
|||
|
||||
@classmethod
|
||||
def from_row(cls, row):
|
||||
inst = cls(*(f.type(r) for f, r in zip(fields(cls), row)))
|
||||
inst = cls(tconst=row[0], averageRating=float(row[1]), numVotes=int(row[2]))
|
||||
assert inst.tconst != r"\N"
|
||||
return inst
|
||||
|
||||
|
|
@ -91,6 +91,8 @@ class RatingRow:
|
|||
return Movie(
|
||||
imdb_id=self.tconst,
|
||||
score=score_from_imdb_rating(self.averageRating),
|
||||
updated=None, # optimization: skip default factory
|
||||
id=None, # optimization: skip default factory
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue