JuliaIO / MeshIO.jl

IO for Meshes
Other
79 stars 31 forks source link

Improve performance of obj file loading #39

Closed rdeits closed 6 years ago

rdeits commented 6 years ago

The load() function for .obj files turned out to be very type-unstable (apparently the element type of eachline() can't be inferred, which meant that almost every single variable was ::Any). Fixing that and a few other minor changes makes OBJ file loading about 10X faster.

Benchmark:

fname = joinpath(Pkg.dir("GeometryTypes"), "test", "data", "cat.obj")
@benchmark MeshIO.load(s, $GLUVMesh) setup=(s = open(FileIO.query(fname))) evals=1

Before:

BenchmarkTools.Trial: 
  memory estimate:  35.44 MiB
  allocs estimate:  795908
  --------------
  minimum time:     478.876 ms (2.74% GC)
  median time:      498.496 ms (2.30% GC)
  mean time:        504.818 ms (1.89% GC)
  maximum time:     558.099 ms (2.22% GC)
  --------------
  samples:          10
  evals/sample:     1

After:

BenchmarkTools.Trial: 
  memory estimate:  13.08 MiB
  allocs estimate:  241044
  --------------
  minimum time:     37.844 ms (0.00% GC)
  median time:      49.456 ms (8.94% GC)
  mean time:        50.454 ms (5.97% GC)
  maximum time:     73.006 ms (0.00% GC)
  --------------
  samples:          99
  evals/sample:     1
SimonDanisch commented 6 years ago

Great! :) Thanks a lot!