Skip to content

Conversation

@mayagbarnes
Copy link
Collaborator

@mayagbarnes mayagbarnes commented Nov 25, 2025

Describe your changes

Attempt to improve initial load time by reducing dependencies included in entry bundle.

Changes made:

  • Reduce protobuf/proto.js size by optimizing flags passed to pbjs
    • Added --no-verify & --no-delimited flags to remove unused verification and delimited encoding functions
    • Reduces entry proto.js from 723 KB to 550 KB (24%)
  • Remove axios from entry bundle
    • Refactor doInitPings to use fetch, lazy load axios in DefaultStreamlitEndpoints when needed

Bundle Analysis:

Before (left): 2.36 MB & After (right): 2.16 MB
Screenshot 2025-11-28 at 1 40 46 a m after

@snyk-io
Copy link
Contributor

snyk-io bot commented Nov 25, 2025

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@mayagbarnes mayagbarnes added change:refactor PR contains code refactoring without behavior change impact:users PR changes affect end users security-assessment-completed Security assessment has been completed for PR labels Nov 25, 2025 — with Graphite App
@github-actions
Copy link
Contributor

github-actions bot commented Nov 25, 2025

✅ PR preview is ready!

Name Link
📦 Wheel file https://core-previews.s3-us-west-2.amazonaws.com/pr-13128/streamlit-1.51.0-py3-none-any.whl
📦 @streamlit/component-v2-lib Download from artifacts
🕹️ Preview app pr-13128.streamlit.app (☁️ Deploy here if not accessible)

Copy link
Collaborator Author

mayagbarnes commented Nov 25, 2025

@mayagbarnes mayagbarnes changed the title Improve proto.js Reduce entry bundle size - Part 5 Nov 25, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Nov 25, 2025

📉 Significant bundle size change detected

Metric This Branch develop Change (%)
Total (gzip) 8.14 MiB 8.16 MiB -0.24%
Entry (gzip) 709.98 KiB 756.8 KiB -6.19%

Please verify that this change is expected.

📊 View detailed bundle comparison

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR reduces the frontend entry bundle size by optimizing the protobuf code generation process. The main optimization adds --no-verify and --no-delimited flags to the pbjs command, which removes unused verification and delimited encoding functions from the generated proto.js file. This achieves a 24% reduction in proto.js size (from 723 KB to 550 KB), resulting in an overall bundle size reduction from 2.15 MB to 1.99 MB.

Key Changes:

  • Added optimization flags (--no-verify, --no-delimited) to pbjs command in the protobuf generation script
  • Added protobufjs as a devDependency in the protobuf package
  • Enhanced the generation script with a postProcess parameter for potential future optimizations

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.

File Description
frontend/protobuf/scripts/generate-proto.js Added --no-verify and --no-delimited flags to pbjs command; added unused postProcess parameter to runCommand function; updated console messages with emojis
frontend/protobuf/package.json Added protobufjs ^7.5.4 as a devDependency
frontend/yarn.lock Updated yarn.lock with new dependency resolutions including protobufjs, @types/node versions, long package, and undici-types

@github-actions
Copy link
Contributor

github-actions bot commented Nov 26, 2025

📈 Frontend coverage change detected

The frontend unit test (vitest) coverage has increased by 0.0200%

  • Current PR: 87.6100% (51245 lines, 6348 missed)
  • Latest develop: 87.5900% (51141 lines, 6346 missed)

✅ Coverage change is within normal range.

📊 View detailed coverage comparison

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 8 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

frontend/connection/src/DoInitPings.tsx:229

  • The status === 0 check may now be unreachable code with native fetch. Unlike axios, the native fetch API throws a TypeError for CORS errors and network failures rather than returning a response with status 0. These errors would be caught by the error.isNetworkError check above (lines 255-271) instead.

While a test exists in utils.test.ts acknowledging this edge case is "rare" with native fetch, consider whether this branch still serves a purpose or if it should be removed to avoid confusion. If keeping it for defensive programming, consider adding a comment explaining why this unlikely case is handled.

          if (status === /* NO RESPONSE */ 0) {
            if (tooManyRetries) {
              LOG.error(
                `Client Error: response received with status ${status} when attempting to reach ${source}`
              )
              sendClientError(
                `Response received with status ${status}`,
                statusText,
                source
              )
            }
            return retryWhenTheresNoResponse()
          }

@mayagbarnes mayagbarnes marked this pull request as ready for review November 26, 2025 05:31
Copy link
Collaborator

@lukasmasuch lukasmasuch left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Base automatically changed from reduce-bundle-4 to develop November 28, 2025 10:59
@mayagbarnes mayagbarnes merged commit 5346abb into develop Nov 28, 2025
45 of 67 checks passed
@mayagbarnes mayagbarnes deleted the reduce-bundle-5 branch November 28, 2025 11:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:refactor PR contains code refactoring without behavior change impact:users PR changes affect end users security-assessment-completed Security assessment has been completed for PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants