Collection#select/#reject copy every component and rebuild its merged data before filtering

Aperta
#154 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
55/100
Tipo di issue
Refactoring
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
ruby
Ambito
performance

Direzione di ricerca

Read lib/compliance_engine/collection.rb, then follow Component#initialize_copy, #element, Data#mapping?, and Data#check_mapping to understand copy isolation and cache rebuilding. Implement equivalent select/reject behavior that duplicates only matching components without changing cache semantics. Use the issue’s 259-file, 2,308-check, and 59-profile dataset to measure heap, RSS, and mapping time; done means the results are correct, isolated, and no longer rebuild discarded components.

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

Descrizione

Collection#select and #reject (lib/compliance_engine/collection.rb) dup the whole collection and then filter it:

result = dup
result.collection = result.to_h.select(&block)

Collection#initialize_copy dups every component, and Component#initialize_copy clears each copy's @fragments/@element caches. The filter block then runs against those fresh copies, so any accessor it calls (for example check.controls or check.ces in Data#mapping?) rebuilds element. element does Marshal.load(Marshal.dump(fragment)) for every fragment before merging.

Data#check_mapping calls checks.select once per profile or CE. With P profiles/CEs and C checks, that is P × C component copies and P × C element rebuilds, and each rebuild Marshal-copies every fragment. Most of those copies belong to checks the filter then throws away.

#150 removed the deep copy of fragments in Component#initialize_copy. That cost is gone, but this per-select rebuild remains.

Suggested approach: run the block against self's components, whose caches are already warm, and dup only the components that match:

def select(&block)
  return to_enum(:select) unless block_given?

  result = dup_without_components   # or equivalent
  result.collection = to_h.select(&block).transform_values(&:dup)
  result
end

(and likewise for reject). Care is needed to keep the copy isolation that initialize_copy guarantees: the returned components must still be independent copies, and the caches on self must reflect the same facts, enforcement tolerance and environment data the copies will use.

It would be worth measuring this the same way as #150 (the 259-file / 2,308-check / 59-profile data set: heap, RSS and time for mapping every profile with facts set).

Lingua principale
Ruby
Stelle
2
Fork
1
Merge medio
3g 6h
PR unite (30g)
4

Preparare l'ambiente

Apri in Codespaces

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

  • Nessun Dockerfile né file Docker Compose
  • Nessun modello di pull request
  • Nessuna guida per i contributori

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 simp/rubygem-simp-compliance_engine

Tutte le issue di simp/rubygem-simp-compliance_engine

Issue simili

Altre issue su Ruby

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.