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

Aperta
#17,773 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

  • #17774 di @rajat315315 — chiusa senza merge

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Tranquilla
Stack tecnologico
java

Direzione di ricerca

Inizia da SimplePropertyDescriptor.getPropertyDescriptors e traccia i suoi chiamanti in JsonOutput e InstanceCoercer. Esamina la cache ConcurrentHashMap proposta, quindi verifica il benchmark e conferma che il comportamento di serializzazione e coercizione rimanga invariato, mentre le ricerche ripetute dei descrittori diventano più veloci.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

A-needs-triaging I-enhancement
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

Lingua principale
Java
Stelle
34.6k
Fork
8.7k
Merge medio
1g 23h
PR unite (30g)
86

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di SeleniumHQ/selenium

Tutte le issue di SeleniumHQ/selenium

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.