python – A section of code runs much faster in Conda environment, Why?

Generally speaking, Python 3.9 and 3.10 have major differences, since Python 3.10 uses Just-In-Time (JIT) compiler that speedups translating Python bytecode into machine code at runtime. Moreover, Conda environment has its own optimizations, specially in dependency management which affect speedups heavily.

BUT your main approach to find the root of the difference should be using a profiler tool. This can be an example:

import cProfile
profiler = cProfile.Profile()
profiler.enable()

if collection.count() == 0:
    collection.add(
    documents=documents, 
    metadatas=metadatas,
    ids=ids
)

profiler.disable()
profiler.print_stats()

Read more here: Source link