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

Reduce bundle size #672

Merged
merged 4 commits into from
Oct 28, 2023
Merged

Reduce bundle size #672

merged 4 commits into from
Oct 28, 2023

Conversation

belgattitude
Copy link
Owner

Reduce bundle size by using class names rather than strings

Importing all exceptions (excluding utilities, typeguards...) now top at 1Kb

Example based on ESM (min+gzip)

Scenario Size
one exception 450b
all exceptions < 1kb
everything (typeguards,...) 1.7kb
  ESM (import everything *)
  Package size is 32 B less than limit
  Size limit: 1.76 kB
  Size:       1.73 kB with all dependencies, minified and gzipped
  
  ESM (only HttpException exception)
  Package size is 1 B less than limit
  Size limit: 395 B
  Size:       394 B with all dependencies, minified and gzipped
  
  ESM (only HttpNotFound exception)
  Package size is 2 B less than limit
  Size limit: 455 B
  Size:       453 B with all dependencies, minified and gzipped
  
  ESM (two client exceptions: HttpNotFound + HttpRequestTimeout)
  Package size is 1 B less than limit
  Size limit: 485 B
  Size:       484 B with all dependencies, minified and gzipped
  
  ESM (only isHttpException)
  Package size is 1 B less than limit
  Size limit: 400 B
  Size:       399 B with all dependencies, minified and gzipped
  
  ESM (only createHttpException)
  Package size is 1 B less than limit
  Size limit: 900 B
  Size:       899 B with all dependencies, minified and gzipped
  
  ESM ({ toJson })
  Package size is 1 B less than limit
  Size limit: 805 B
  Size:       804 B with all dependencies, minified and gzipped
  
  ESM ({ fromJson })
  Package size is 635 B less than limit
  Size limit: 2 kB
  Size:       1.36 kB with all dependencies, minified and gzipped
  
  CJS (require everything *)
  Package size is 32 B less than limit
  Size limit: 2.3 kB
  Size:       2.27 kB with all dependencies, minified and gzipped
  
  CJS (only isHttpException)
  Package size is 2 B less than limit
  Size limit: 1.35 kB
  Size:       1.35 kB with all dependencies, minified and gzipped
  

@changeset-bot
Copy link

changeset-bot bot commented Oct 28, 2023

🦋 Changeset detected

Latest commit: b37b2cf

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@httpx/exception Minor
@examples/nextjs-app Patch
@httpx/json-api Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@ghost
Copy link

ghost commented Oct 28, 2023

👇 Click on the image for a new way to code review

Review these changes using an interactive CodeSee Map

Legend

CodeSee Map legend

@codecov
Copy link

codecov bot commented Oct 28, 2023

Codecov Report

Merging #672 (b37b2cf) into main (55080b3) will decrease coverage by 1.23%.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #672      +/-   ##
==========================================
- Coverage   92.10%   90.87%   -1.23%     
==========================================
  Files          72       74       +2     
  Lines         557      482      -75     
  Branches      117      118       +1     
==========================================
- Hits          513      438      -75     
  Misses         38       38              
  Partials        6        6              
Flag Coverage Δ
httpx-dsn-parser-unit 100.00% <ø> (ø)
httpx-exception-unit 91.94% <100.00%> (-1.48%) ⬇️
httpx-json-api-unit 66.00% <ø> (ø)
Files Coverage Δ
packages/exception/src/base/HttpClientException.ts 100.00% <100.00%> (ø)
packages/exception/src/base/HttpException.ts 100.00% <100.00%> (ø)
packages/exception/src/base/HttpServerException.ts 100.00% <100.00%> (ø)
packages/exception/src/client/HttpBadRequest.ts 100.00% <100.00%> (ø)
packages/exception/src/client/HttpConflict.ts 100.00% <100.00%> (ø)
...ages/exception/src/client/HttpExpectationFailed.ts 100.00% <100.00%> (ø)
...kages/exception/src/client/HttpFailedDependency.ts 100.00% <100.00%> (ø)
packages/exception/src/client/HttpForbidden.ts 100.00% <100.00%> (ø)
packages/exception/src/client/HttpGone.ts 100.00% <100.00%> (ø)
packages/exception/src/client/HttpImATeapot.ts 100.00% <100.00%> (ø)
... and 37 more

@belgattitude belgattitude merged commit 9d1d248 into main Oct 28, 2023
9 checks passed
@belgattitude belgattitude deleted the size-improved branch October 28, 2023 15:03
@belgattitude belgattitude mentioned this pull request Oct 28, 2023
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.

1 participant