When using multiple objects or big data structures, a way to improve its performance is to use delay loading or assignment (to implement). Time -to -time operations have been shortened as possible as possible, never realized. I use some examples to explain how delayed loading technology is used in Java, and gives some guidelines that can be easier (used) and as part of core language in other languages.
A use scenario is to show hundreds of metadata and measurement objects worthy of domain objects through JTable. Initialize our domain objects that can save two types of objects in memory, even if only some metadata are displayed in the form. It takes a few seconds to build this form, and (but) we can accept hundreds of (data) again. After doing some analysis, we improved our realization, and it looks like this:
Public class domainObject {Private Final DataParser Parser; Private Final Map <string, String> Header = New HashMap <(); Private Final List <data> Data = New ARR aylist <> (); Public Dom ArinObject (DataParser Aparser) {Parser = Aparser;} Public String GetHeaderField (String name) {// Here we lazily Parse and file the header map (header.isempl ()) {header.addall (Parser.Header ());} Return header.get (name) ;} Public iterable <data> GetmeasurementValues () {// Again lazy-load and parse the data if (data.isempty ()) {data.addall (PARSER.MEASUREMENTS ());} Return data;}}
This improvement improves the entry of display time and significantly improves our (capabilities) of our processing big data items. All data load occurs only when someone wants to view the measurement of the measurement and double -click a certain item.
A kind of java will be delayed after the box is dismantled.
// Lazy and Fast BeCAUSE The Expense Operation Will Only Execute When NEEDEDIF (Acondition () && Expensiveoperation ()) {...} // Slow Order (Still Lazy ED!) If (Expensiveoperation () && Acondition ()) {. ..}
The long -lasting layer framework like Hibernate often defaults to delay loading because the database access and the data transmission price is quite high under normal circumstances.
Most language functions are based on surround delay assignment. This theoretical function is like the first class of all members to maximize the effects of side effects on delay. SCALA mixes object -oriented language functions and introduces delayed keywords to simplify the Java style. The delayed initial code is like the following
Public Class Dom ArinObject (Parser: DataParser) {// Evaluated on First Access Private Lazy Val Header = {Parser.Header ()} DEF GETHEADERELD (name: string): s tring = {header.get (name) .getorelse ("") } // Evaluated on First Access Lazy Val MesurementValues: ITERABLE [data] = {Parser.measurements ()}}}
in conclusion
Delaying loading is not a new revolutionary technology, but it is a very useful tool when dealing with big data or slowing resources. In many cases you can use it to improve performance or use it yourself.
It can reduce the cost of implementing code. If the language support is not very good (like Java) and other cases, it is necessary to feel more response in pre -compilation and pre -processing.