Skip to content

Conversation

@JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Feb 2, 2026

I've seen many performance-critical functions that have calls to time.time(), which is perhaps not that surprising. I don't want to just add a primitive for time.time(), since it's often monkey patched, and primitive functions generally can't be monkey patched. Instead, I add the librt.time module here, which has an efficient time() function that can be used in performance-critical code (but it can't be monkey patched).

In a microbenchmark this was up to 70% faster than using time.time().

I used a lot of coding agent assist. I'm relying on CI to test the Windows implementation.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 2, 2026

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

extra_compile_args=cflags,
),
Extension(
"librt.time", ["time/librt_time.c"], include_dirs=["."], extra_compile_args=cflags
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add "time" to include_dirs?

["vecs/librt_vecs.h", "vecs/vec_template.c"],
["vecs"],
),
ModDesc("librt.time", ["time/librt_time.c"], ["time/librt_time.h"], []),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also would make sense to add the include dir here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants