chore(activityCatalog): optimize page size #40
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR refactors the data loading of the activity catalog to optimize its page size. Currently, the activity catalog is 3mb uncompressed (431kb compressed) which severely degrades performance and incurs bandwidth costs.
Background
The activity catalog uses a full-text search database called Orama. To eliminate the need to fetch data asynchronously, the original implementation serialized the Orama database to json on the server side and passed back to the client which deserializes it. Additionally, the server pre-rendered all 150+ activities and added it to the HTML response. The net effect is that all activity renders, the serialized database (which contains the same activities) were added to the payload.
Optimization
To optimize this, only the first 8 activities (the first two rows on the largest screen size) will be serialized (instead of all 100+ activities). The client will be responsible for loading the database asynchronously and populating the remaining activities. This optimization effectively allows the perceived performance to be high by pre-rendering only content above the fold. The remaining activities will be rendered in asynchronously after the page has loaded.
Perforamnce Gains
In testing, the current page is approximately 3mb uncompresed and 431kb compressed. It has a lighthouse performance score of 58.
After these changes, the page size is 972kb uncompressed and 120kb compressed (a 3x improvement). It has a lighthouse performance score of 72.
Before
After