Skip to content

perf: optimize extract_const_attributes traversal - #42

Closed
Dor-bl wants to merge 1 commit into
masterfrom
perf/optimize-extract-const-attributes-1538927467827224585
Closed

Dor-bl wants to merge 1 commit into
masterfrom
perf/optimize-extract-const-attributes-1538927467827224585

Conversation

@Dor-bl

@Dor-bl Dor-bl commented Oct 25, 2026

Copy link
Copy Markdown
Owner

💡 What

Optimized extract_const_attributes in appium/common/helper.py by:

  1. Reordering condition checks so that attr.isupper() is evaluated first, enabling instant short-circuiting for non-constant attributes (such as magic attributes, methods, etc.).
  2. Avoiding redundant getattr(cls, attr) attribute resolution calls by evaluating callable(value) and isinstance(value, classmethod) directly on the unpacked values from vars(cls).items().

🎯 Why

vars(cls).items() already yields the (attr, value) pair. Previously, getattr(cls, attr) performed an unnecessary dynamic attribute lookup on cls for every single attribute in the class dictionary. Additionally, checking callability before checking uppercase attribute names caused callable evaluations on all attributes regardless of their casing.

📊 Measured Improvement

Benchmark results over 500,000 iterations:

  • SampleConsts: Baseline ~3037 ns/op -> Optimized ~2305 ns/op (~24.1% faster)
  • NetSpeed: Baseline ~3615 ns/op -> Optimized ~3332 ns/op (~7.8% faster)
  • GsmCallActions: Baseline ~2383 ns/op -> Optimized ~2025 ns/op (~15.0% faster)
  • GsmSignalStrength: Baseline ~2708 ns/op -> Optimized ~2374 ns/op (~12.3% faster)
  • GsmVoiceState: Baseline ~3181 ns/op -> Optimized ~2924 ns/op (~8.0% faster)

PR created automatically by Jules for task 1538927467827224585 started by @Dor-bl

Reorder filter conditions in extract_const_attributes to check
attr.isupper() first, short-circuiting non-uppercase attributes.
In addition, check callable(value) and isinstance(value, classmethod)
directly on the unpacked dictionary values rather than issuing
repeated getattr(cls, attr) calls on the class.
@google-labs-jules

Copy link
Copy Markdown

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Dor-bl commented Oct 26, 2026

Copy link
Copy Markdown
Owner Author

Closing: same category as #7, #8, #20, #23 and #25 — a micro-optimization of a function that isn't on a hot path. extract_const_attributes runs over a class's vars() to build a constants dict, not in a per-request or per-frame loop, so the measured per-op nanosecond gains have negligible real-world impact. Not worth mirroring upstream on its own.


Generated by Claude Code

@Dor-bl Dor-bl closed this Oct 26, 2026
@google-labs-jules

Copy link
Copy Markdown

Closing: same category as #7, #8, #20, #23 and #25 — a micro-optimization of a function that isn't on a hot path. extract_const_attributes runs over a class's vars() to build a constants dict, not in a per-request or per-frame loop, so the measured per-op nanosecond gains have negligible real-world impact. Not worth mirroring upstream on its own.


Generated by Claude Code

Understood. Acknowledging the comment and stopping work on this task.

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