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

async loading #521

Merged
merged 21 commits into from
Mar 12, 2025
Merged

async loading #521

merged 21 commits into from
Mar 12, 2025

Conversation

AnnMarieW
Copy link
Collaborator

@AnnMarieW AnnMarieW commented Mar 2, 2025

Closes #367

Implementing Async Loading for Improved Performance

This will reduce initial load times and improve performance, especially for apps using only a subset of the available components.

Reduction in dash_mantine_components.js file size:

  • before changes: 2.68 MiB
  • after async loading for all the charts: 1.71MiB 🎉
  • after async loading for all code highlight components: 823 KiB 🥳

Maybe move the following to a future PR?

Add async loading to all the files in these folders:

  • dates
  • notifictions
  • npropgress
  • core:

In the core folder, the largest files only:

Size (KB) File Name
56 MultiSelect.py
52 TagsInput.py
52 Select.py
48 Autocomplete.py
44 Modal.py
40 ColorInput.py
36 LoadingOverlay.py
32 Tooltip.py
32 Drawer.py
28 NumberInput.py
28 JsonInput.py
28 FloatingTooltip.py
28 Button.py
28 ActionIcon.py
24 TimeInput.py
24 TextInput.py
24 Textarea.py
24 RangeSlider.py
24 PasswordInput.py

@AnnMarieW
Copy link
Collaborator Author

@alexcjohnson

I'm just getting started on this project and have applied async loading to the AreaChart and BarChart. With just these two components updated, the dash_mantine_components.js file size has already been reduced from 2.68 MiB to 2.18 MiB 🎉.

I'm following the approach Emil used for async loading in dash-leaflet:

Before applying these changes to all the other files, I’d love to get your input on the following:

  • Is it okay to place a fragments folder inside each component directory (charts, core, dates, extensions)? Any potential issues with this approach?
  • There seems to be some redundancy in prop definitions between the component and the fragment. Is there a way to optimize this?
  • Am I missing anything important, or is there anything unnecessary in the current setup?
  • Any other comments?

Looking forward to your thoughts! 😊

@alexcjohnson
Copy link
Collaborator

Is it okay to place a fragments folder inside each component directory (charts, core, dates, extensions)? Any potential issues with this approach?

That should be fine.

There seems to be some redundancy in prop definitions between the component and the fragment. Is there a way to optimize this?

You can't directly import the fragment in the wrapper, but the reverse is OK: you should be able to import the interface from the wrapper, like we do with props in some older components

In the core folder, the largest files only

These are the Python files? Those don't say much about the size of the code they use, just about the props they support but that's heavily duplicated vs the JS code. I'd go one-by-one thinking about the complexity of what these components likely do in JS, and make fragments according to your judgment on that. So great call starting with charts, after which datepickers seem like a great next step but I don't yet have a great sense of what all is in Mantine to know if there are other candidates for high-code components.

@AnnMarieW
Copy link
Collaborator Author

AnnMarieW commented Mar 7, 2025

@alexcjohnson

What do you think is the minimum size difference to make it worthwhile doing the async loading? I just tried the Carousel and CarouselSlide and I was surprised to see it didn't make that much difference. The dash_mantine_components.js went from 1.71 to 1.69 MiB

Next did the three code highlight components: CodeHighlight, CodeHighlightTabs InlineCodeHighlight - those made a big difference!

  • dash_mantine_components.js (823 KiB)
  • dash_mantine_components-shared.js (1.33MiB)

However, now that the dash_mantine_components-shared.js is so large, is there still the same benefit? If people don't use the charts or the code highlight components, will this shared file not have to be loaded?

@AnnMarieW AnnMarieW marked this pull request as ready for review March 7, 2025 19:47
@AnnMarieW AnnMarieW requested a review from alexcjohnson March 7, 2025 19:47
@emilhe
Copy link
Contributor

emilhe commented Mar 11, 2025

@alexcjohnson

What do you think is the minimum size difference to make it worthwhile doing the async loading? I just tried the Carousel and CarouselSlide and I was surprised to see it didn't make that much difference. The dash_mantine_components.js went from 1.71 to 1.69 MiB

Next did the three code highlight components: CodeHighlight, CodeHighlightTabs InlineCodeHighlight - those made a big difference!

  • dash_mantine_components.js (823 KiB)
  • dash_mantine_components-shared.js (1.33MiB)

However, now that the dash_mantine_components-shared.js is so large, is there still the same benefit? If people don't use the charts or the code highlight components, will this shared file not have to be loaded?

I have made a PR trying to mitigate this issue.

emilhe and others added 2 commits March 12, 2025 08:59
… DRY). Tests run; they all pass except for "test_002rc_radio_group_deselectable"
Split shared chart resources into a separate chunk
Copy link
Collaborator

@alexcjohnson alexcjohnson left a comment

Choose a reason for hiding this comment

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

💃 Great job @AnnMarieW - and fantastic contribution @emilhe 🎉

@AnnMarieW
Copy link
Collaborator Author

Thanks @emilhe 🎉

@AnnMarieW AnnMarieW merged commit fc61140 into snehilvj:master Mar 12, 2025
1 check passed
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.

Large Bundle Size for dash_mantine_components.js
3 participants