SeleniumHQ / SeleniumHQ/selenium

[🚀 Feature]: Performance bottleneck in SimplePropertyDescriptor due to redundant reflection lookup

Open
#17,773 2 comments 0 reactions 0 assignees View on GitHub
A-needs-triaging I-enhancement
Dominant language
Java
Stars
34.5k
Forks
8.7k
Avg merge
2d 1h
Merged PRs (30d)
92

Description

### Description

**Description:**
Currently, `SimplePropertyDescriptor.getPropertyDescriptors` is called on every serialization and coercion run in the custom JSON library (via `JsonOutput` and `InstanceCoercer`).

Inside the method, it calls `clazz.getMethods()` to inspect properties (getters/setters). In JVM implementations (like HotSpot), `Class.getMethods()` is relatively expensive because the JVM does not return a shared array; it has to copy the array and clone/instantiate new `Method` reflection objects on every single invocation.

Since the properties and methods of a Java class do not change at runtime, we can avoid this overhead by caching the resolved property descriptors in a `ConcurrentHashMap`.

A quick micro-benchmark running 200,000 lookups on a target capabilities class shows:
* **Without cache**: ~907 ms (Avg: ~4,535 ns per lookup)
* **With cache**: ~9 ms (Avg: ~46 ns per lookup)
* **Lookup speedup**: ~96.8x faster

This also speeds up the overall end-to-end serialization (`json.toJson`) by ~18% even for a simple capabilities class with few properties.

I have a branch ready with this optimization and will open a PR.

### Have you considered any alternatives or workarounds?

_No response_

Contributor guide

Open the contributing guide

Research direction

Start at SimplePropertyDescriptor.getPropertyDescriptors and trace its callers in JsonOutput and InstanceCoercer. Review the proposed ConcurrentHashMap cache, then verify the benchmark and confirm serialization and coercion behavior remain unchanged while repeated descriptor lookups become faster.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend, performance
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.