ThinkR-open / ThinkR-open/datadiff
[perf] compute_tolerance_ok : bascule sur le kernel complet (~12x plus lent) dès le premier NA — un fast-path intermédiaire suffit
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 6
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
Contexte
compute_tolerance_ok() (R/tolerance.R) a un fast-path (3 passes) réservé aux colonnes sans aucun NA/NaN/Inf. Dès qu'une colonne contient un seul NA — le cas le plus courant en données réelles (bench lyon-na de dev/bench/perf_issue4.R) — elle bascule sur le kernel complet compute_tolerance_col() et ses ~15 passes vectorielles (7 masques dont certains redondants : both_nan ⊂ both_na en R).
Mesures (200 k lignes, R 4.3.3) :
- kernel complet : 0,0175 s/colonne — 11,7× le fast-path (0,0015 s) ;
- kernel intermédiaire « NA sans NaN/Inf » (ok brut +
ok[is.na(ok)] <- FALSE+ correctionboth_na) : 0,004 s — 4,4× plus rapide que le complet, résultat bit-identique (vérifié).
Extrapolé au bench lyon-na (500 col × 300 k) : ~13 s → ~3 s sur ce poste.
Reprex (bench)
n <- 2e5
ref <- rnorm(n); cand <- ref + 1e-12
cand[sample(n, 100)] <- NA # 0,05 % de NA suffisent à payer 12x
bench::mark(
fast = datadiff:::compute_tolerance_ok(ref, ref, 1e-9, 0, TRUE), # sans NA
complet = datadiff:::compute_tolerance_ok(cand, ref, 1e-9, 0, TRUE), # avec NA
check = FALSE
)
Critères de succès
- Fast-path de 2e niveau : colonnes avec NA mais sans NaN/Inf traitées sans le kernel complet ; garde basée sur
any(is.nan(.))/any(is.infinite(.))plutôt queanyNAseul. - Équivalence bit-à-bit avec
compute_tolerance_col()$okverrouillée par test (NA, NaN, Inf, mixtes,na_equalTRUE/FALSE) — extension de test-tolerance-ok.R. - Nettoyage des masques redondants du kernel complet (
both_nan/one_naninclus dansboth_na/one_na) sans changement de résultat. - Gain mesuré sur le scénario lyon-na du bench documenté dans NEWS.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in R/tolerance.R by reading compute_tolerance_ok() and compute_tolerance_col(), then inspect test-tolerance-ok.R and the lyon-na benchmark in dev/bench/perf_issue4.R. Done means the NA-only fast path is covered by bit-identical tests across NA, NaN, Inf, mixed values, and both na_equal settings, redundant masks are cleaned up without changing results, and the benchmark gain is documented in NEWS.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- performance
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100