Refactoring in preparation for `AffineSpace` #80

merged 20 commits into from Nov 30, 2012


None yet

2 participants


These are all of the changes in my affine-space branch up to the actual switch over to Point, which as has been documented elsewhere still suffers from a performance hit. These patches, however, incur no such hit. In fact, if anything timings improve,


benchmarking Object 1/STL write
collecting 100 samples, 1 iterations each, in estimated 753.4876 s
mean: 251.7557 ms, lb 246.6139 ms, ub 259.6708 ms, ci 0.950
std dev: 32.41427 ms, lb 23.54860 ms, ub 45.75001 ms, ci 0.950
found 8 outliers among 100 samples (8.0%)
  3 (3.0%) high mild
  5 (5.0%) high severe
variance introduced by outliers: 86.287%
variance is severely inflated by outliers

benchmarking Object 2/STL write
collecting 100 samples, 1 iterations each, in estimated 135.6434 s
mean: 1.753192 ms, lb 1.505299 ms, ub 2.359345 ms, ci 0.950
std dev: 1.836184 ms, lb 552.7734 us, ub 3.251082 ms, ci 0.950
found 17 outliers among 100 samples (17.0%)
  16 (16.0%) high severe
variance introduced by outliers: 98.986%
variance is severely inflated by outliers


benchmarking Object 1/STL write
collecting 100 samples, 1 iterations each, in estimated 741.8008 s
mean: 239.5342 ms, lb 238.1994 ms, ub 240.8767 ms, ci 0.950
std dev: 6.889492 ms, lb 6.210129 ms, ub 7.795821 ms, ci 0.950
variance introduced by outliers: 23.820%
variance is moderately inflated by outliers

benchmarking Object 2/STL write
collecting 100 samples, 1 iterations each, in estimated 102.2284 s
mean: 1.457241 ms, lb 1.406844 ms, ub 1.537824 ms, ci 0.950
std dev: 319.5546 us, lb 232.6374 us, ub 493.9032 us, ci 0.950
found 22 outliers among 100 samples (22.0%)
  7 (7.0%) high mild
  15 (15.0%) high severe
variance introduced by outliers: 95.701%
variance is severely inflated by outliers

Moreover, these are nice cleanups (many of them moving towards a coordinate-free representation) and merging them early will greatly reduce the work required to keep affine-space up to date until the performance issues have been sorted out.

bgamari added some commits Nov 29, 2012
@bgamari bgamari Remove killed sources from cabal file d7aef24
@bgamari bgamari Export/RayTrace: Make things typecheck

         Couldn't match type `ℝ' with `Int'
         When using functional dependencies to combine
           Additive ℕ ℝ ℝ,
             arising from the dependency `a b -> c'
             in the instance declaration at
           Additive Int ℝ Int,
             arising from a use of `+'
             at Graphics/Implicit/Export/RayTrace.hs:213:65
         In the first argument of `xy', namely `(a + s)'
         In the second argument of `($)', namely `xy (a + s) (b + s)'

I'm not sure how this could have worked previously. Perhaps this is a
GHC 7.6-ism?
@bgamari bgamari Util/OVal: Enable -XFlexibleInstances
Seems to be necessary for things to build
@bgamari bgamari Add simple Criterion benchmark 89b82dc
@bgamari bgamari Begin porting things to vector-space
This follows the approach taken in Brent Yorgey's diagrams package,
using Conal Elliott's vector-space classes. This allows us to get rid of
the rather unidiomatic and arguably overly-polymorphic
Graphics.Implicit.SaneOperators. Since this has been removed, we can now
begin pulling out the many type annotations strewn about the codebase.

The recently introduced Criterion benchmark confirms that this has no
measurable effect on performance,

                        Before              After
Object 1/STL write      235.7 ± 9.3 ms      236.0 ± 12.8 ms
Object 2/STL write      1.54  ± 0.99 ms     1.44  ± 0.28 us

Note that I make no attempt to enforce any separate between AffineSpaces
and VectorSpaces here. This is work for a later patch.

Additionally, a small performance gain may be had by strictifying and
unpacking the fields of R3 and R2. This, however, would require that a
`data` type be defined and all packing/unpacking of vectors would need
to happen with the appropriate data constructor. Given this is even more
invasive a change than the current patch, this is left as future work.

@bgamari bgamari MarchingSquares: Refactor to avoid breaking up vectors 4faac84
@bgamari bgamari RayTrace: Avoid breaking up vectors f8452a5
@bgamari bgamari Render: Avoid splitting up vectors into components 32e9106
@bgamari bgamari GetLoops: Spelling fix 238899b
@bgamari bgamari TriangleMeshFormats: Fix indentation 84072ed
@bgamari bgamari Util: Fix trailing whitespace 507b767
@bgamari bgamari Implicit.Export.Util.normVertex: Avoid spllitting up vectors 43faf3e
@bgamari bgamari Export.Util: Introduce centroid
This is a pattern which appears quite frequently.
@bgamari bgamari GetSegs: Use centroid ffc0140
@bgamari bgamari RefineSegs: Use centroid 789a3f7
@bgamari bgamari TesselateLoops: Use centroid b922f8a
@bgamari bgamari GetBox2: Reduce code duplication 6cbe608
@bgamari bgamari GetBox3: Deduplicate outsetBox db2ff81
@bgamari bgamari GetImplicit3: Kill extraneous type annotations 2f6e1ca
@bgamari bgamari extopenscad: Avoid breaking up vector bad8efe
@colah colah merged commit 11855f3 into colah:master Nov 30, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment