Skip to content

perf: replace pathlib with os.path.basename in logging.py#8

Closed
KRRT7 wants to merge 1 commit intomasterfrom
perf/os-path-logging
Closed

perf: replace pathlib with os.path.basename in logging.py#8
KRRT7 wants to merge 1 commit intomasterfrom
perf/os-path-logging

Conversation

@KRRT7
Copy link
Copy Markdown
Owner

@KRRT7 KRRT7 commented Apr 9, 2026

Summary

Replace from pathlib import Path + Path(x).name with os.path.basename(x) in RichHandler.render(). os is already imported transitively and available at near-zero cost, while pathlib adds ~4-5ms to the RichHandler import path.

This is also a minor runtime improvement: os.path.basename is a simple string operation vs Path object construction + attribute access.

Testing

952 passed on CPython 3.9–3.14 and PyPy 3.10.

Replace `from pathlib import Path` + `Path(x).name` with
`os.path.basename(x)`. os is already imported transitively and
available at near-zero cost, while pathlib adds ~4-5ms to the
RichHandler import path.

This is also a minor runtime improvement: os.path.basename is a
simple string operation vs Path object construction + attribute access.
@KRRT7
Copy link
Copy Markdown
Owner Author

KRRT7 commented Apr 9, 2026

Superseded by the consolidated stacked PRs #12 + #13.

@KRRT7 KRRT7 closed this Apr 9, 2026
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.

1 participant