imports not properly cached under pypy3
TLDR: originally this started out as an issue about strptime
, but it turns code like the following is the cause:
import time
def smuggler():
"""Secretly imports things"""
import datetime
NUM = 1000 * 1000
t0 = time.time()
for _ in range(NUM):
smuggler()
t1 = time.time()
print("Smuggled {} modules in {}s".format(NUM, t1 - t0))
Running this gives us:
$ pypy importer.py
Smuggled 1000000 modules in 0.0068838596344s
$ pypy3 importer.py
Smuggled 1000000 modules in 10.808286428451538s
Original strptime benchmark:
from datetime import datetime
from random import randint
from time import time
NUMBER = 1000 * 1000
def randdate():
y = str(randint(1900, 2100))
m = str(randint(1, 12)).zfill(2)
d = str(randint(1, 28)).zfill(2)
return "{}-{}-{}T00:00:00".format(y, m, d)
print("Building dates")
dates = [randdate() for _ in range(NUMBER)]
print("Done - proceeding to parse")
while True:
t0 = time()
for d in dates:
datetime.strptime(d, "%Y-%m-%dT%H:%M:%S")
t1 = time()
print("Took {}s ({}/s)".format(t1 - t0, int(NUMBER / (t1 - t0))))
On my system it produces the following eventual numbers:
pypy3.7-7.3.4 Took 12.74s (78474/s)
pypy2.7-7.3.3 Took 1.60s (623199/s)
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information