Skip to content

perf: speed up area-weighted interpolation - #16

Merged
mountainMath merged 1 commit into
mountainMath:v0.3.8from
dshkol:perf/v0.3.8-optimizer
Aug 24, 2026
Merged

perf: speed up area-weighted interpolation#16
mountainMath merged 1 commit into
mountainMath:v0.3.8from
dshkol:perf/v0.3.8-optimizer

Conversation

@dshkol

@dshkol dshkol commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Speeds up tongfen_estimate() while preserving its existing API and output semantics.

Changes

  • Remove unnecessary casting of every intersection geometry to MULTIPOLYGON.
  • Calculate source geometry areas once, then index them for each intersection.
  • Scale all variables in one batch instead of repeatedly calling mutate().
  • Replace deprecated tidyselect usage encountered on this path.
  • Add tests covering:
    • Multiple additive variables
    • Geometry preservation
    • na.rm = TRUE and na.rm = FALSE

Performance

Benchmark fixture:

  • 2,500 source polygons
  • 2,500 offset target polygons
  • 40 additive variables
  • Seven timed iterations after warm-up
  • R 4.5.0, sf 1.0.23, dplyr 1.1.4
Revision Median Range
v0.3.8 0.667s 0.651–0.711s
Candidate 0.207s 0.195–0.216s

Speedup: 3.22×

Complete outputs from separately installed baseline and candidate packages were equivalent using:

all.equal(
baseline,
candidate,
check.attributes = TRUE,
tolerance = 1e-12
)

Validation

  • Full test suite passes.
  • Source package builds successfully with vignettes.
  • R CMD check --no-manual: Status OK
  • No new dependencies.
  • No public API changes.

@mountainMath
mountainMath merged commit 8c5913c into mountainMath:v0.3.8 Aug 24, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants