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

Abierto
#154 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
55/100
Tipo de issue
Refactorización
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
ruby
Área
performance

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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).

Lenguaje dominante
Ruby
Estrellas
2
Forks
1
Merge medio
3 d 6 h
PR fusionados (30 d)
4

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

  • Sin Dockerfile ni archivo de Docker Compose
  • Sin plantilla de pull request
  • Sin guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de simp/rubygem-simp-compliance_engine

Todos los issues de simp/rubygem-simp-compliance_engine

Issues similares

Más issues de Ruby

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.