From c31873f724b60bc0d83a0f3fd5939169efeadd8f Mon Sep 17 00:00:00 2001 From: spillerrec Date: Thu, 20 Mar 2014 00:49:30 +0100 Subject: [PATCH] IMPROVE: reuse previous allocated memory when reallocating for slight speedup. #15 --- lib/MeshModel.dart | 19 +++++++++++--- tool/mesh_efficiency.dart | 54 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 tool/mesh_efficiency.dart diff --git a/lib/MeshModel.dart b/lib/MeshModel.dart index 4aaaa1f..7bdcc67 100644 --- a/lib/MeshModel.dart +++ b/lib/MeshModel.dart @@ -6,26 +6,39 @@ abstract class Drawable3D{ void draw_lines( Float32List vertices, int amount ); } +List unused = new List(); class DynamicFloat32List{ + Float32List create( int wanted ){ + for( int i=0; i= wanted ) + return unused.removeAt(i); + } + return new Float32List( wanted ); + } + Float32List list; int length = 0; void addAll( Float32List add, Matrix4 offset ){ if( list == null ){ //List doesn't exist - list = new Float32List.fromList( add ); + list = create( add.length ); + for( int i=0; i load( String url ) => new File( url ).readAsString(); +} + +class Debug extends Progress{ + + @override + void updated() { + if( current == total ){ + MeshModel model = new MeshModel(); + + + Stopwatch watch = new Stopwatch(); + watch.start(); + loader.file.to_mesh( model, new LDrawContext() ); + print( "to_mesh took: ${watch.elapsed}" ); + watch.reset(); + new Float32List( 3244032*10 ); + print( "create took: ${watch.elapsed}" ); + + int amount = 0, amount_real = 0; + + print( "lines:" ); + model.lines.values.forEach( (f){ + print( f.vertices.length ); + amount += f.vertices.length; + amount_real += f.vertices.list.length; + }); + print( "\ntriangles:" ); + model.triangles.values.forEach( (f){ + print( "${f.vertices.length} \t\t\t ${f.vertices.list.length}" ); + amount += f.vertices.length; + amount_real += f.vertices.list.length; + }); + + print( "Needed memory: ${ amount * 4 / 1024 / 1024 } MiB" ); + print( "Used memory: ${ amount_real * 4 / 1024 / 1024 } MiB" ); + print( "unused size: ${unused.length}" ); + unused.forEach((f){ + print( f.length ); + }); + } + } +} +LDrawLoader loader; +void main(){ + loader = new LDrawLoader( new LDrawFileLib(), "Keywriter.mpd", new Debug() ); +} \ No newline at end of file