Skip to content

Implement an Applicator WithTrait #305

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
May 1, 2025
Merged

Implement an Applicator WithTrait #305

merged 10 commits into from
May 1, 2025

Conversation

asinghvi17
Copy link
Member

@asinghvi17 asinghvi17 commented May 1, 2025

This lets the trait, known by apply anyway, pass into the target function. It's mostly a convenience thing but can cut down on some allocs. Centroid does get 1000 less allocs from this, but the other improvements I made to it outshine it.

Changelog:

  • Introduce a new Applicator WithTrait((trait, obj; kw...) -> ...) (but it usually won't get any kw, I filter the standard ones out)
  • Improve the performance of area and centroid

This is really useful in fix and prepare. They are kind of the same thing but I am going to prototype the new fix pipeline in prepare. It's really needed, ironically, for geom-geom distance queries. Those are n^2 unless you can do some form of branch and bound on spatial trees of the geom or rings.

asinghvi17 added 7 commits May 1, 2025 06:34
This significantly decreases allocs.

In centroid, 17k allocs are from the actual centroid impl which needs to be looked at.  But many allocs are from type uncertainty and trait.  We cut down 1000 allocs in centroid.  Area was far more affected.

### Before
```julia
julia> @be GO.centroid($geoms)
Benchmark: 73 samples with 1 evaluation
 min    1.259 ms (27439 allocs: 864.547 KiB)
 median 1.298 ms (27439 allocs: 864.547 KiB)
 mean   1.368 ms (27439 allocs: 864.547 KiB, 0.99% gc time)
 max    5.351 ms (27439 allocs: 864.547 KiB, 72.51% gc time)
```
### After
```julia
julia> @be GO.centroid($geoms) gc=true
Benchmark: 73 samples with 1 evaluation
 min    1.233 ms (26080 allocs: 815.000 KiB)
 median 1.301 ms (26080 allocs: 815.000 KiB)
 mean   1.380 ms (26080 allocs: 815.000 KiB, 1.11% gc time)
 max    7.332 ms (26080 allocs: 815.000 KiB, 80.89% gc time)
```
@asinghvi17 asinghvi17 requested a review from rafaqz May 1, 2025 10:58
@rafaqz
Copy link
Member

rafaqz commented May 1, 2025

This is great. But my main comment is that apply(ApplyWithTrait is a bit confusing, to me apply(WithTrait(f) is cleaner language.

(also there is no particuar reason it would only be used in apply)

@asinghvi17 asinghvi17 changed the title Implement an Applicator ApplyWithTrait Implement an Applicator WithTrait May 1, 2025
@asinghvi17 asinghvi17 merged commit bf1ad62 into main May 1, 2025
10 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