Conversation
Remove Python 2 compatibility layer since Python 2 is no longer supported.
This simplifies the codebase and improves performance by eliminating
unnecessary type checks and function call overhead.
Changes:
- Remove compat module usage from all main source files
- Replace smart_decode() with direct str() or .decode("utf-8") calls
- Use Python 3 built-ins directly (str, bytes, int, range, Queue, Thread)
- Simplify encode_bytearray/decode_bytearray functions
- Change encode_float to use str() instead of repr() (identical in Python 3)
Benchmark results (isolated microbenchmarks):
- str() vs smart_decode() for integers: 1.90x faster
- str() vs smart_decode() for booleans: 2.61x faster
- str() vs smart_decode() for Decimal: 1.75x faster
- .decode("utf-8") vs smart_decode() for stream reading: 2.01x faster
- Combined protocol overhead reduction: ~15-18%
The compat module is kept for backwards compatibility with any external
code that may import from it, but is no longer used internally.
Co-Authored-By: Claude <noreply@anthropic.com>
Wires the perf framework's micro scenarios (M1-M7) and four representative macro scenarios (X1-1, X2-10k, X4, X6) into CodSpeed's walltime measurement on bare-metal Macro Runners. What it gives us: - per-PR regression detection on Python protocol code paths (M5-M7: encode int/string/float, decode int/string, escape/unescape) - macro-level regression detection on the round-trip-heavy hot paths (X2 javalist iteration, X4 callback round-trips, X6 pool saturation) - per-commit perf trend on master - bare-metal measurement environment (<1% variance vs. shared CI noise) Triggers are intentionally minimal: push to master tracks the trend, workflow_dispatch lets maintainers run on a PR when a change claims a perf impact. No PR auto-trigger to keep macro-runner minutes lean. Macros are exposed via a small pytest-codspeed adapter at src/py4j/tests/perf/scenarios/codspeed_macros.py - re-uses the existing MacroScenario classes from scenarios/macro.py, one parametrize entry per scenario, so each becomes its own tracked benchmark on the CodSpeed dashboard. Prerequisite (maintainer action, not in this PR): - Install the CodSpeed GitHub App on the py4j org: https://github.com/apps/codspeed - Set the CODSPEED_TOKEN repository secret (provided by the App). Until the App is installed, this workflow's job won't pick up a runner (codspeed-macro label) and CI on this workflow will queue. No effect on existing workflows or test runs. Co-authored-by: Isaac
Merging this PR will improve performance by 27.7%
Performance Changes
Tip Curious why this is faster? Comment Comparing Footnotes
|
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.
Test PR for CodSpeed integration on byteoak fork.
Re-applies upstream py4j#575 (remove Python 2 compat + smart_decode
optimization) on top of byteoak/py4j master, with the CodSpeed
integration commit cherry-picked.
Purpose: validate that CodSpeed posts PR-level perf comparisons
automatically when a PR touches Python source. Throwaway PR — not for
merge.