Skip to content

Table widget refactors#1776

Merged
DavBfr merged 2 commits into
DavBfr:masterfrom
grahamsmith:table_multi_page
Nov 26, 2024
Merged

Table widget refactors#1776
DavBfr merged 2 commits into
DavBfr:masterfrom
grahamsmith:table_multi_page

Conversation

@grahamsmith

Copy link
Copy Markdown
Contributor

Started looking to see if the Multipage and Table performance can be enhanced with larger datasets.

Thought a small PR to start with would be easier.

Refactored to eliminate nullable doubles and reduce force unboxing.

@grahamsmith

Copy link
Copy Markdown
Contributor Author

@DavBfr I think my formatter is different to yours, are you at 80 chars?

bottom: side,
left: side,
horizontalInside: side,
verticalInside: side,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added trailing comma to force formatting


final double? width;
final double? flex;
final double width;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the null here makes the amount the work later on easier. I couldn't find a case where they would be.

final columnWidth = columnWidths != null && columnWidths![n] != null
? columnWidths![n]!
: defaultColumnWidth;
for (final entry in row.children.asMap().entries) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully this is a bit more legible and no longer has to worry about null as much

@DavBfr

DavBfr commented Nov 12, 2024

Copy link
Copy Markdown
Owner

@DavBfr I think my formatter is different to yours, are you at 80 chars?

Yes I am using the default remanded dart formatting.

@grahamsmith

Copy link
Copy Markdown
Contributor Author

I'll update with 80 chars.

It'll be the same code.

@grahamsmith

Copy link
Copy Markdown
Contributor Author

@DavBfr - sorted - line lengths are 80 so the diff is simpler now

Unsure about the CI failures from the last run

@grahamsmith

Copy link
Copy Markdown
Contributor Author

@DavBfr - in my next PR I have extracted the width calculation to its own function, and added it what I hope would be a decent performance enhancement to reuse the calculations if all the column widths are fixed. It would mean we wouldn't have to calculate for every multipage page the width again.

@grahamsmith

Copy link
Copy Markdown
Contributor Author

@DavBfr - sorry not relevant to this PR but do not know where else to post as too excited

before my changes for a demo pdf with 10,000 items into a table it took 0:00:57.012834
my new fork with changes 0:00:11.770033

Nothing too major either!

Much excite

@DavBfr

DavBfr commented Nov 14, 2024

Copy link
Copy Markdown
Owner

Congrats!

@grahamsmith

Copy link
Copy Markdown
Contributor Author

I noticed the checks have passed, do I need to do anything else @DavBfr ?

@DavBfr

DavBfr commented Nov 14, 2024

Copy link
Copy Markdown
Owner

Just need some time to review.

@DavBfr DavBfr mentioned this pull request Nov 14, 2024
3 tasks
@Gustl22

Gustl22 commented Nov 14, 2024

Copy link
Copy Markdown
Contributor

@grahamsmith this will potentially conflicting with #1736, where some changes to the algorithm were made. Hope we find a good solution to make it perform good also with cell spans enabled (haven't tested the performance yet, though).

@grahamsmith

Copy link
Copy Markdown
Contributor Author

I imagine it will be terrible, although a potential useful feature.

I have more changes in the background that greatly enhance the performance of the layout as its quite slow as other's have mentioned.

Wonder if the spanning could be in a specific set of widgets. In a perfect world would really love to know how many users need cell spanning (clearly you did).

@grahamsmith

Copy link
Copy Markdown
Contributor Author

@Gustl22 - do you know when your changes will land? I am not particularly precious about this PR. One of the biggest gains is in MultiPage so I can do a seperate PR for that and hopefully it will not clash.

@Gustl22

Gustl22 commented Nov 14, 2024

Copy link
Copy Markdown
Contributor

do you know when your changes will land?

No I don't, open source takes time, just wanted to make aware of this conflict. I am also lacking the time to review my stuff in my repos.

Wonder if the spanning could be in a specific set of widgets. In a perfect world would really love to know how many users need cell spanning (clearly you did).

At least 14 people created or upvoted an issue regarding that. And I think the most people are working around this by creating nested tables or column and row layouts, but that's not the clean way. I don't mind which one is merged first, I also have to create performance tests.

There surely can made also optimizations, especially if no cell span is present.

@DavBfr DavBfr merged commit c49c37d into DavBfr:master Nov 26, 2024
@DavBfr

DavBfr commented Nov 26, 2024

Copy link
Copy Markdown
Owner

Thanks!

fchamone added a commit to fchamone/dart_pdf that referenced this pull request Feb 25, 2025
@Gustl22

Gustl22 commented Feb 25, 2025

Copy link
Copy Markdown
Contributor

@grahamsmith Can you share your performance test?

I executed following:

  test('Table Widget multi-pages with header', () {
    pdf.addPage(MultiPage(
      maxPages: 10000,
        build: (Context context) => <Widget>[
              Table(
                children: buildTable(
                    context: context, count: 10000, repeatHeader: true),
                border: TableBorder.all(),
                tableWidth: TableWidth.max,
              ),
            ]));
  });

Before your changes:
image

With your changes:

image

So I only got a difference from about 4-10 seconds improvements, but not 46 (?)
Which is an improvement, but I just wanted to verify how big.

@grahamsmith

Copy link
Copy Markdown
Contributor Author

I did not keep a copy sorry!

From memory I inserted a string with the item count e.g. 'item $index' into a cell on each row of 10000 rows.

Performance tests vary per machine setup too so are usually subjective.

@Gustl22

Gustl22 commented Feb 25, 2025

Copy link
Copy Markdown
Contributor

Thank you, ya just wanted to make this more objective. I repeated the tests multiple times.

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

Successfully merging this pull request may close these issues.

3 participants