Monday, January 14, 2008

[TECH] Ideas for Optimizing Design pattern implementations with Stack Collapsing

One major drawback I guess with all these object oriented systems I guess is performance, since people write the code so that its extensible it always ends up creating deep stack sizes, recently I was looking into (Jmol) this structure visualization tool supports several input format descriptions for the structures (pdb,cif,molxyz....). This is how they hide format details from the display code
JmolAdapter (abstract class)
==> SmarterJmolAdapter (this contains a interface called AtomSetCollection ). So depending on the input file we have several AtomSetCollection readers like PdbAtomSetCollection etc...

Although I came to a conclusion that to implement the structural alignment algorithm into Jmol, I need to implement this AtomSetCollection which structurally aligns the protein structures, but I guess there are several draw backs of the implementation of object oriented java implementation, the cost of creating an extensible design does not come for free it comes at the cost of performance, I found that a simple command execution could end up creating a stack size of 32 this is what concerns me is there a way we can collapse the stack when we know that the intermediate functions on the stack are just delegating the call to the actual instance, I guess this STACK COLLAPSING technique can always be applied when ever the Adapter design pattern is used. For example see the below stack of size 32, its not doing any thing great its just opening a new script file, because of the way the code is written (use of design patterns) the stack size seem to increase a lot and ULTIMATELY ALL THESE PATTERNS ARE JUST DELEGATING A FUNCTION CALL TO TO FUNCTION ON TOP OF THE STACK, I'm think of ways to improve the delegation since at each level of the stack you are doing a look up and it increases linearly with the size of the stack.

  [1] org.jmol.viewer.ScriptManager.addScript (
  [2] org.jmol.viewer.ScriptManager.addScript (
  [3] org.jmol.viewer.Viewer.evalStringQuiet (,152)
  [4] org.jmol.viewer.Viewer.evalString (,119)
  [5] org.jmol.viewer.Viewer.openFile (,379)
  [6]$OpenAction.actionPerformed (,435)
  [7] javax.swing.AbstractButton.fireActionPerformed (,849)
  [8] javax.swing.AbstractButton$Handler.actionPerformed (,169)
  [9] javax.swing.DefaultButtonModel.fireActionPerformed (
  [10] javax.swing.DefaultButtonModel.setPressed (
  [11] javax.swing.AbstractButton.doClick (
  [12] javax.swing.plaf.basic.BasicMenuItemUI.doClick (,051)
  [13] javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased (,092)
  [14] java.awt.Component.processMouseEvent (,517)
  [15] javax.swing.JComponent.processMouseEvent (,135)
  [16] java.awt.Component.processEvent (,282)
  [17] java.awt.Container.processEvent (,966)
  [18] java.awt.Component.dispatchEventImpl (,984)
  [19] java.awt.Container.dispatchEventImpl (,024)
  [20] java.awt.Component.dispatchEvent (,819)
  [21] java.awt.LightweightDispatcher.retargetMouseEvent (,212)
  [22] java.awt.LightweightDispatcher.processMouseEvent (,892)
  [23] java.awt.LightweightDispatcher.dispatchEvent (,822)
  [24] java.awt.Container.dispatchEventImpl (,010)
  [25] java.awt.Window.dispatchEventImpl (,791)
  [26] java.awt.Component.dispatchEvent (,819)
  [27] java.awt.EventQueue.dispatchEvent (
  [28] java.awt.EventDispatchThread.pumpOneEventForHierarchy (
  [29] java.awt.EventDispatchThread.pumpEventsForHierarchy (
  [30] java.awt.EventDispatchThread.pumpEvents (
  [31] java.awt.EventDispatchThread.pumpEvents (
  [32] (

No comments: