chore: minor cleanups and perf tweaks from code review#2910
Open
henryiii wants to merge 1 commit into
Open
Conversation
- util/file.py, util/python_build_standalone.py: use hashlib.file_digest for streaming SHA-256 verification instead of loading whole archives into memory with read_bytes() - logger.py: convert colors/symbols properties to functools.cached_property so the Colors/Symbols objects are constructed only once per Logger instance - platforms/windows.py: remove redundant .strip() on where_pip (already stripped at assignment) - util/python_build_standalone.py: remove unreachable python_base_dir.exists() guard (callers always pass a fresh temp subdirectory) - util/file.py: add comment explaining the getattr shim for tar_.extraction_filter and when it can be removed Assisted-by: ClaudeCode:claude-fable-5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 AI text below 🤖
This PR addresses items 5-9 from the code review checklist in #2908 with five small cleanup/perf fixes:
Streaming SHA-256 verification (
util/file.py,util/python_build_standalone.py): Replacehashlib.sha256(path.read_bytes()).hexdigest()withhashlib.file_digest(f, "sha256").hexdigest()to avoid loading entire archives (potentially hundreds of MB) into memory at once.hashlib.file_digestwas added in Python 3.11.0, which is the minimum supported version.functools.cached_propertyforLogger.colors/Logger.symbols(logger.py): TheColorsandSymbolsobjects were reconstructed on every property access, butcolors_enabledandunicode_enablednever change after__init__. Converting tocached_propertyavoids the repeated allocations.Remove redundant
.strip()(platforms/windows.py):where_pipwas already.strip()-ed at assignment (line 329); the duplicate call on line 331 was dead code.Remove unreachable
python_base_dir.exists()guard (util/python_build_standalone.py): Both callers ofcreate_python_build_standalone_environmentpass a fresh temp subdirectory, so the guard can never trip. Verified by inspectingpyodide.py(passestmp / "base") andandroid.py(passes a newlymkdir-edbuild_path).Comment explaining the
getattrshim (util/file.py): Notes why the shim is needed (Python 3.11.0-3.11.3 support) and what the cleanup looks like once the minimum is raised to 3.11.4+/3.12.Part of #2908
🤖 Generated with Claude Code