J2ME performance optimization tips & tricks
Upcoming SlideShare
Loading in...5

J2ME performance optimization tips & tricks






Total Views
Views on SlideShare
Embed Views



6 Embeds 4,089

http://www.codinguru.com 4057
url_unknown 15
http://translate.googleusercontent.com 8
http://webcache.googleusercontent.com 7
http://mobilegametutorials.blogspot.com 1
http://hghltd.yandex.net 1



Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.


11 of 1

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

    J2ME performance optimization tips & tricks J2ME performance optimization tips & tricks Presentation Transcript

    • Micro Java
      Performance Tuning & optimization
    • Device limitations
      Runtime memory
      Processor speed
      Slow network bandwidth
      Screen resolutions
      Restricted storage
    • Performance Tuning
      Tips & tricks
      Good & ugly practice
      Performance tuning
      Tools usages
      Effective usages of design patterns
    • Tips & tricks
      Use “Out of memory Exception” handlers on each initialization
      Avoid inner classes: make the main class implement the required Listener interfaces and handle the call-backs there.
      Collapse inheritance hierarchy, even it means duplicating code
      Shorten all name qualifiers (package, class, method, variable names)
      Minimize the number of array
      Reduce try-catch blocks to bare minimum
      Use lower versions of JDK while packaging JAR files, JAR File size created using JDK 1.3 is 5% to 20% lesser than those created with JDK1.4.
      Scope of variables/classes/methods can impact performance
      Eliminate unnecessary type casts
    • Tips & tricks-II
      Compound operators are faster, because fewer byte codes are generated
      Define methods that accept reusable objects to be filled in with data, rather than methods that return objects holding that data
      Inline methods where ever it is possible.
      Use private and static methods and final classes to encourage in lining by the compiler.
      keep synchronized method out of loop, it increases the overhead
      Avoid synchronization where ever its possible
      Minimize using the methods use native call
      Be specific for throwing and handling exceptions
    • Creating objects in loop
      Imposes double penalty in terms of performance
      Each iteration in loop pushes the runtime system closer to garbage collector
      Restructure code instead creating new processor each time
    • Good practice
      Bad practice
      Object[] inputs = new Object[0];
      int[] results = new int[0];
      int length = inputs.length;
      Processor p = new Processor();
      for (int i = 0; i < length; i++) {
      results[i] = p.calculateResult();
      Object[] inputs = new Object[0];
      int[] results = new int[0];
      int length = inputs.length;
      for (int i = 0; i < length; i++) {
      Processor p = new Processor(inputs[i]);
      results[i] = p.calculateResult();
    • String & Stringbuffer
      String is only the data type which can overload + operator in java
      Each time you connate a string it inters creates a string buffer and string buffer creates performs over byte array
      String buffer in efficient then string, but not always
    • Performance Tuning
    • BE clean
      Release resource
      Free the used internal data structures
      Set array references to null after usage
      Close network connections in finally block
    • Optimizing User interface
      Need to be simple, fast, informative and responsive
      Progress indicator while network / other processing
      Usage of low resolution images maintaining the minimal quality
      Use double buffering technique for images where ever it applies
      Use client caching
      Use paint or partial paint the screen where ever necessary
    • Optimizing Application deployment
      Usage of obfuscator packages
      Usage of low resolution images maintaining the minimal quality
      Include only the classes you need
      Use public variables in your classes, rather than using assessors. It is practically bad practice but reduces app size
      Use protected methods
    • Use of obfuscator
      Reduces .jar size
      Byte code obfuscator makes the code difficult to decompile
      Side effect- descriptive method and variable names gets converted to small machine generated names
      Obfuscators are
      Retro guard
      Pro guard
      IBM JAX
    • Benchmarking
      J2SE has many tools for benchmarking
      In ME we use “java.lang.runtime” class methods for memory test
    • Knowing the runtime free memory
      Runtime runtime = Runtime.getRuntime();
      long before, after;
      before = runtime.freeMemory();
      Object newObject = new String();
      after = runtime.freeMemory();
      long size = before - after;
    • Knowing execution time for a method
      Use System.currentTimeMiles()
      long start, finish;
      start = System.currentTimeMillis();
      finish = System.currentTimeMillis();
      long duration = finish - start;
    • MIDP Performance monitor Tools
      Collects the statistics of application
      Tools used in J2ME wireless tool kit are:
      Memory monitor
      Network monitor
    • Midlet Profiler
      Collects the statistics of application
      To monitor the method call and time to execute a method
      Includes MIDP reference implementation classes
    • Call Graph
    • Memory monitor
      Object Graph
    • Network Monitor
      Request Response
    • Conclusion
      Only optimize code if you need to and where it counts
      Always study your code and try to improve the algorithms before using low-level techniques
      Use setClip() where possible to minimize the drawing area
      Keep as much stuff as possible out of loops
      Pre-calculate and cache like crazy
      Use static final methods where possible and avoid the synchronized modifier
      Pass as few parameters as possible into frequently-called methods
      Try to compare to zero instead of any other number
      Local variables are faster than instance variables