Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • pypy pypy
  • Project information
    • Project information
    • Activity
    • Labels
    • Planning hierarchy
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 650
    • Issues 650
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 13
    • Merge requests 13
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • PyPy
  • pypypypy
  • Issues
  • #3431

Closed
Open
Created Apr 09, 2021 by Oliver Margetts@olliemathDeveloper

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)
Edited Apr 09, 2021 by Oliver Margetts
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking