java - Programming: Equivalent function but different(ly optimized) implemention and automatic (cached) choice before each execution - How? -
a function may work on cpu on gpu, both same job.
sure, want use gpu-solution (assuming it's faster), not available on -for example- let's older opengl version.
instead of programming check (if available use "this" else "that") on each function call, may want call 1 function trough reference bound function call.
to go further optimization, imagine 4 solutions:
- cpu + optimized small pictures
- cpu + optimized big pictures
- gpu + optimized small pictures
- gpu + optimized big pictures
now, not (as programmer) have eliminate 2 possibilities depending on old/new "opengl version", have choose 1 of 2 remaining possibilities depending on usage.
some calls have small or big pictures function parameters, in others places of code, need choose function want call depending on picture-parameter's values. - 4x4 pixel pictures or small lookup-tables cpu-solution fastest (lower overhead)
one solution make function code paths split , lead optimized functions. works same package, not different packages providing same function (example: standard-library vs driver-library/hooks)
another solution write jet package incorporates used ones , chooses function optimized task. jet -even uglier- solution update each function call hand.
but solution searching uses function reference each call given function @ program-loading time, depending on hardware or software environment.
it should able change when dependency-libraries load or unload. (for example: new version of other library installed, old 1 uninstalled while program running - or waiting during execution of thread on cpu-core)
the program shouldn't bother if there 1 or more functions under name. should bother what's fastest execute.
example:
- package pictures; //has averageredvalue( byte[height][width][rgb] )
- package images; //has averageredvalue( byte[height][width][rgb] ) too
if both give same result, why should programmer care 1 used? wants fast solution or option read settings-file.
and end-user wants simple option choose same functions used in past date - asks version control , rollback features
please tell me if have seen solution or idea at.
this rather confused, normal case, solution trivial: write interface containing needed methods , make sure best implementation gets loaded.
the jit determines there's 1 such implementation (class hierarchy analysis) , calls proper method directly.
it should able change when dependency-libraries load or unload.
java can't efficiently. whenever second implementation gets loaded, optimized code must thrown away , methods recompiled. conditional branch still pretty cheap, more implementations loaded gets slower.
there's no way unload class without using classloader magic.
what need for?
Comments
Post a Comment