2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2020

04/22/2004: POI Optimization - Speeding up org.apache.poi.hssf.usermodel.HSSFSheet.setPropertiesFromSheet()

This setPropertiesFromSheet() method potentially logs a lot of information. The logging calls are expensive because of the objects created when assembling the log messages. Using the check() method of the logging sub-system can prevent object creation when debugging is turned off. This change reduced execution time of my test case by 14.2 seconds and prevented the creation of 781,632 objects.

    /**
     * used internally to set the properties given a Sheet object
     */
    private void setPropertiesFromSheet(Sheet sheet) {
        long timestart = 0; // only used for debugging.
        int sloc = sheet.getLoc();
        RowRecord row = sheet.getNextRow();

        while (row != null) {
            createRowFromRecord(row);
            row = sheet.getNextRow();
        }
        sheet.setLoc(sloc);
        CellValueRecordInterface cval = sheet.getNextValueRecord();

        if (log.check(DEBUG)) {
            timestart = System.currentTimeMillis();
            log.log(DEBUG, "Time at start of cell creating in HSSF sheet = ", new Long(timestart));
        }
        HSSFRow lastrow = null;

        while (cval != null) {
            long cellstart = System.currentTimeMillis();
            HSSFRow hrow = lastrow;

            if ((lastrow == null) || (lastrow.getRowNum() != cval.getRow())) {
                hrow = getRow(cval.getRow());
            }
            if (hrow != null) {
                lastrow = hrow;
                if (log.check(DEBUG)) {
                    log.log(DEBUG, "record id = " + Integer.toHexString(((Record) cval).getSid()));
                }
                hrow.createCellFromRecord(cval);
                cval = sheet.getNextValueRecord();
                if (log.check(DEBUG)) {
                    log.log(DEBUG, "record took ", new Long(System.currentTimeMillis() - cellstart));
                }
            } else {
                cval = null;
            }
        }
        if (log.check(DEBUG)) {
            log.log(DEBUG, "total sheet cell creation took ", new Long(System.currentTimeMillis() - timestart));
        }
    }

04/22/2004: POI Optimization - Speeding up org.apache.poi.hssf.record.BlankRecord.compareTo()

This optimization is nearly identical to the one applied to HSSFRow.compareTo() - just used a local copy of the row and column values. This change reduced exceution time in my test case by 17.5 seconds.

    /**
     * switched to using a local copy of the row and column. Also moved the equality test to
	 * the last test because it is most complex and probably least likely to be true.
     */
    public int compareTo(Object obj) {
        int rv = -1;
        CellValueRecordInterface loc = (CellValueRecordInterface) obj;

        int thisRow = this.getRow();
        int locRow = loc.getRow();

        if (thisRow < locRow) {
            rv = -1;
        } else if (thisRow > locRow) {
            rv = 1;
        } else {
            int thisColumn = this.getColumn();
            int locColumn = loc.getColumn();

            if (thisColumn > locColumn) {
                rv = 1;
            } else if (thisColumn < locColumn) {
                rv = -1;
            } else if ((thisRow == locRow) && (thisColumn == locColumn)) {
                rv = 0;
            }
        }
        return rv;
    }