java - JRuby, large arrays, and performance issues in a real-time application -


i'm working on real-time game application. of written in java, decided experiment moving of initialization procedures jruby scripts in order maximize ease player modify how world generated.

as start, decided move map generation jruby script. @ present, boils down following java code:

scriptingcontainer container = new scriptingcontainer(); container.put("$data", datapackage); container.runscriptlet(pathtype.relative, scriptname); datapackage = (blockmapgenerationdatapackage)container.get("$data"); 

the data package contains information necessary java program produce final terrain , render it, , contains necessary data in order ruby script able craft manner of maps. in particular, contains rather large array (currently 1000 x 1000 x 15). test whether ruby script working, i've stripped out entire map generation algorithm , put in following extremely simple test:

require 'java' dir["../../dist/\*.jar"].each { |jar| require jar }  in (0...$data.getwidth())   j in (0...$data.getdepth())     $data.blocks[i][j][0] = java::blockmap::blocktype::grass   end end 

this executed once upon initialization. when implemented in java, far more memory intensive generation algorithms, there no performance or memory issues of kind. game ran smoothly @ hundreds of frames per second @ high resolutions on old laptop 1000 x 1000 x 15 map. however, when java generation code replaced above jruby script, program appears suffer memory consumption issues: frame rate drops 30-40 fps , program freezes maybe 10th of second @ impressively consistent periodic rate of once every 3 seconds. profiling , various tests reveal possible culprit ruby script.

moreover, if size of map drastically reduced, 100 x 100 x 15, these issues more or less disappear.

i've tried various things adding container.terminate(); or container.clear(); after java code execute script, don't understand source of issue or how fix it. i'd appreciate if explain what's going wrong here , whether or not can fixed!

it might best make map creation routine separate app altogether chains java app.

i'm pretty sure memory layout of arrays in jruby going different , causing problems--the map object may created different memory layout requiring ongoing jruby interaction whenever accessed, or simple creating integers instead of ints , aren't noticing because of autoboxing (again, total guess since can't see data types)


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -