Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-4469

Optimize import time of ObjectID

    • Type: Icon: Improvement Improvement
    • Resolution: Won't Do
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Python Drivers
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      ObjectID takes a while to import because of these calls:

      from random import SystemRandom
      ...
      class ObjectId:
          _pid = os.getpid()
      
          _inc = SystemRandom().randint(0, _MAX_COUNTER_VALUE)
          _inc_lock = threading.Lock()
      
          __random = _random_bytes()
      

      It should be possible to defer some of these calls to the first time ObjectId is used.

      Update: It's actually the from random import SystemRandom import which takes long time, not the SystemRandom() call itself.

            Assignee:
            Unassigned Unassigned
            Reporter:
            shane.harvey@mongodb.com Shane Harvey
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: