Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A quick question regarding performance (fastness of reading writing) #117

Open
Tanzin01 opened this issue May 7, 2024 · 1 comment
Open

Comments

@Tanzin01
Copy link

Tanzin01 commented May 7, 2024

Hello there, hope you are having a good day

Short version: Is this wrapper faster?

here i go: I tried the apacge poi library for a file which have 62 cells. Only 7 cells have minimal text, rests are empty. However to my wonder, its taking quite some time to read the cells and store them in a list variable as a result recyclerView appears a lot later than my other views makes ui screen unintuitive and odd.

So, i was wondering if your wrapper version would be faster?
I used them-

implementation 'org.apache.poi:poi-ooxml:5.2.3' // Use an older version that doesn't rely on MethodHandle
    implementation 'org.apache.poi:poi:5.2.3'// Use an older version that doesn't rely on MethodHandle

And the code(if it explains more)-

public List<List<String>> readExcel() {
    List<List<String>> rows = new ArrayList<>();
    try (FileInputStream fis = new FileInputStream(filePath);
         Workbook workbook = WorkbookFactory.create(fis)) {

        Sheet sheet = workbook.getSheetAt(0); // Assuming we are reading the first sheet
        
        int batchSize = Math.min(100, sheet.getPhysicalNumberOfRows()); // Read rows in batches, up to 100 rows
        int rowCount = sheet.getPhysicalNumberOfRows();
        for (int startRow = 0; startRow < rowCount; startRow += batchSize) {
            int endRow = Math.min(startRow + batchSize, rowCount);
            for (int rowNum = startRow; rowNum < endRow; rowNum++) {
                Row row = sheet.getRow(rowNum);
                if (row != null) {
                    List<String> cells = new ArrayList<>();
                    for (int colNum = 0; colNum < row.getLastCellNum(); colNum++) {
                        Cell cell = row.getCell(colNum, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK);
                        String cellValue = getCellValueAsString(cell);
                        cells.add(cellValue);
                    }
                    rows.add(cells);
                }
            }
        }
    } catch (IOException e) {
        Log.e(TAG, "Error reading Excel file", e);
    }
    return rows;
}

or am i doing something terribly wrong?

@centic9
Copy link
Owner

centic9 commented May 10, 2024

Code looks fine on a quick look.

But with the description above I am not sure what exactly is slow for you: do you see slowness when using the poi-on-android jar-file compared to some other approach or do you see slowness in one version compared to another?

For analyzing performance issues it is often a very good idea to use some sort of profiling to analyze what actually causes the issue as the problem very often is not what you initially expect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants