Skip to content

Commit

Permalink
Improve prod bundle size (#2447)
Browse files Browse the repository at this point in the history
Greatly improve production build size, now prod builds are 1/3 of the size
 - Main spacedrive binary went from ~120M to ~40M
 - Add more optimize options for rust prod build
 - Improve vite settings for front-end prod build
 - Improve lossless compression of PNGs
 - Don't include videos in bundles when they are not used
 - Don't generate/bundle sourcemap for prod builds
  • Loading branch information
HeavenVolkoff authored May 7, 2024
1 parent a238760 commit 81c2b8b
Show file tree
Hide file tree
Showing 240 changed files with 54 additions and 15 deletions.
8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,11 @@ opt-level = 3
[profile.dev.package."*"]
opt-level = 3
incremental = false

# Optimize release builds
[profile.release]
panic = "abort" # Strip expensive panic clean-up logic
codegen-units = 1 # Compile crates one after another so the compiler can optimize better
lto = true # Enables link to optimizations
opt-level = "s" # Optimize for binary size
strip = true # Remove debug symbols
Binary file modified apps/desktop/app-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions apps/desktop/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,11 @@ default = ["custom-protocol"]
devtools = ["tauri/devtools"]
ai-models = ["sd-core/ai"]
custom-protocol = ["tauri/custom-protocol"]

# Optimize release builds
[profile.release]
panic = "abort" # Strip expensive panic clean-up logic
codegen-units = 1 # Compile crates one after another so the compiler can optimize better
lto = true # Enables link to optimizations
opt-level = "s" # Optimize for binary size
strip = true # Remove debug symbols
Binary file modified apps/desktop/src-tauri/dmg-background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified apps/desktop/src-tauri/icons/128x128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified apps/desktop/src-tauri/icons/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified apps/desktop/src-tauri/icons/Square107x107Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified apps/desktop/src-tauri/icons/Square142x142Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified apps/desktop/src-tauri/icons/Square150x150Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified apps/desktop/src-tauri/icons/Square284x284Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified apps/desktop/src-tauri/icons/Square310x310Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified apps/desktop/src-tauri/icons/Square44x44Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified apps/desktop/src-tauri/icons/Square89x89Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified apps/desktop/src-tauri/icons/StoreLogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified apps/desktop/src-tauri/icons/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions apps/desktop/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ export default defineConfig(({ mode }) => {
server: {
port: 8001
},
build: {
rollupOptions: {
treeshake: 'recommended',
external: [
// Don't bundle Fda video for non-macOS platforms
process.platform !== 'darwin' && /^@sd\/assets\/videos\/Fda.mp4$/
].filter(Boolean)
}
},
plugins: [
devtoolsPlugin,
process.env.SENTRY_AUTH_TOKEN &&
Expand Down
Binary file modified apps/landing/public/apple-touch-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified apps/landing/public/favicon-16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified apps/landing/public/favicon-32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified apps/landing/public/images/app/gradient-overlay.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified apps/landing/public/images/contextmenu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified apps/landing/public/images/explorer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified apps/landing/public/images/icons/image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified apps/landing/public/images/icons/texturedmesh.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified apps/landing/public/images/june-23-alpha-release.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified apps/landing/public/images/logo-192x192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified apps/landing/public/images/logo-512x512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified apps/landing/public/images/misc/blueplanet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified apps/landing/public/images/misc/icongrid.png
Binary file modified apps/landing/public/images/october-23-alpha-release.png
Binary file modified apps/landing/public/images/quickpreview.png
Binary file modified apps/landing/public/images/spacedrive-feb-2024-release.png
Binary file modified apps/landing/public/logo.png
Binary file modified apps/landing/src/app/logo.png
Binary file modified apps/landing/src/app/opengraph-image.png
Binary file modified apps/mobile/assets/icon.png
Binary file modified apps/mobile/assets/splash.png
2 changes: 1 addition & 1 deletion apps/mobile/src/screens/onboarding/GetStarted.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useNavigation, useRoute } from '@react-navigation/native';
import { AppLogo, BloomOne } from '@sd/assets/images';
import { SdMobIntro } from '@sd/assets/videos';
import SdMobIntro from '@sd/assets/videos/SdMobIntro.mp4';
import { ResizeMode, Video } from 'expo-av';
import { Image } from 'expo-image';
import { MotiView } from 'moti';
Expand Down
Binary file modified apps/web/public/logo-192x192.png
Binary file modified apps/web/public/logo-512x512.png
Binary file modified apps/web/screenshots/overview-dark.png
Binary file modified apps/web/screenshots/overview-light.png
Binary file modified docs/product/assets/roadmap/folder.png
26 changes: 24 additions & 2 deletions interface/app/onboarding/full-disk.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Fda } from '@sd/assets/videos';
import { useEffect, useState } from 'react';
import { useNavigate } from 'react-router';
import { Button } from '@sd/ui';
import { Icon } from '~/components';
Expand All @@ -8,18 +8,40 @@ import { usePlatform } from '~/util/Platform';
import { OnboardingContainer, OnboardingDescription, OnboardingTitle } from './components';

export const FullDisk = () => {
const [fdaVideo, setFdaVideo] = useState<string | null>(null);
const { requestFdaMacos } = usePlatform();
const navigate = useNavigate();

const { t } = useLocale();

useEffect(() => {
import('@sd/assets/videos/Fda.mp4').then(
(module) => {
setFdaVideo(module.default);
},
(err) => {
console.error(err);
navigate('../locations', { replace: true });
}
);
});

return (
<OnboardingContainer>
<Icon name="HDD" size={80} />
<OnboardingTitle>{t('full_disk_access')}</OnboardingTitle>
<OnboardingDescription>{t('full_disk_access_description')}</OnboardingDescription>
<div className="mt-5 w-full max-w-[450px]">
<video className="rounded-md" autoPlay loop muted controls={false} src={Fda} />
{fdaVideo && (
<video
className="rounded-md"
autoPlay
loop
muted
controls={false}
src={fdaVideo}
/>
)}
</div>
<div className="flex items-center gap-3">
<Button onClick={requestFdaMacos} variant="gray" size="sm" className="my-5">
Expand Down
Binary file modified packages/assets/icons/Album-20.png
Binary file modified packages/assets/icons/Album.png
Binary file modified packages/assets/icons/Album_Light.png
Binary file modified packages/assets/icons/Alias-20.png
Binary file modified packages/assets/icons/Alias.png
Binary file modified packages/assets/icons/Alias_Light.png
Binary file modified packages/assets/icons/AmazonS3.png
Binary file modified packages/assets/icons/AndroidPhotos.png
Binary file modified packages/assets/icons/AppleFiles.png
Binary file modified packages/assets/icons/Application.png
Binary file modified packages/assets/icons/Application_Light.png
Binary file modified packages/assets/icons/Archive-20.png
Binary file modified packages/assets/icons/Archive.png
Binary file modified packages/assets/icons/Archive_Light.png
Binary file modified packages/assets/icons/Audio-20.png
Binary file modified packages/assets/icons/Audio.png
Binary file modified packages/assets/icons/Audio_Light.png
Binary file modified packages/assets/icons/BackBlaze.png
Binary file modified packages/assets/icons/Ball.png
Binary file modified packages/assets/icons/Book-20.png
Binary file modified packages/assets/icons/Book.png
Binary file modified packages/assets/icons/BookBlue.png
Binary file modified packages/assets/icons/Book_Light.png
Binary file modified packages/assets/icons/Box.png
Binary file modified packages/assets/icons/Code-20.png
Binary file modified packages/assets/icons/Collection-20.png
Binary file modified packages/assets/icons/Collection.png
Binary file modified packages/assets/icons/CollectionSparkle.png
Binary file modified packages/assets/icons/CollectionSparkle_Light.png
Binary file modified packages/assets/icons/Collection_Light.png
Binary file modified packages/assets/icons/Config-20.png
Binary file modified packages/assets/icons/DAV.png
Binary file modified packages/assets/icons/Database-20.png
Binary file modified packages/assets/icons/Database.png
Binary file modified packages/assets/icons/Database_Light.png
Binary file modified packages/assets/icons/DeleteLocation.png
Binary file modified packages/assets/icons/Document-20.png
Binary file modified packages/assets/icons/Document.png
Binary file modified packages/assets/icons/Document_Light.png
Binary file modified packages/assets/icons/Document_doc.png
Binary file modified packages/assets/icons/Document_doc_Light.png
Binary file modified packages/assets/icons/Document_pdf.png
Binary file modified packages/assets/icons/Document_pdf_Light.png
Binary file modified packages/assets/icons/Document_xls.png
Binary file modified packages/assets/icons/Document_xls_Light.png
Binary file modified packages/assets/icons/Document_xmp.png
Binary file modified packages/assets/icons/Dotfile-20.png
Binary file modified packages/assets/icons/Drive-AmazonS3.png
Binary file modified packages/assets/icons/Drive-AmazonS3_Light.png
Binary file modified packages/assets/icons/Drive-BackBlaze.png
Binary file modified packages/assets/icons/Drive-BackBlaze_Light.png
Binary file modified packages/assets/icons/Drive-Box.png
Binary file modified packages/assets/icons/Drive-DAV.png
Binary file modified packages/assets/icons/Drive-DAV_Light.png
Binary file modified packages/assets/icons/Drive-Darker.png
Binary file modified packages/assets/icons/Drive-Dropbox.png
Binary file modified packages/assets/icons/Drive-Dropbox_Light.png
Binary file modified packages/assets/icons/Drive-GoogleDrive.png
Binary file modified packages/assets/icons/Drive-GoogleDrive_Light.png
Binary file modified packages/assets/icons/Drive-Mega.png
Binary file modified packages/assets/icons/Drive-Mega_Light.png
Binary file modified packages/assets/icons/Drive-OneDrive.png
Binary file modified packages/assets/icons/Drive-OneDrive_Light.png
Binary file modified packages/assets/icons/Drive-OpenStack.png
Binary file modified packages/assets/icons/Drive-OpenStack_Light.png
Binary file modified packages/assets/icons/Drive-PCloud.png
Binary file modified packages/assets/icons/Drive-PCloud_Light.png
Binary file modified packages/assets/icons/Drive-box_Light.png
Binary file modified packages/assets/icons/Drive.png
Binary file modified packages/assets/icons/Drive_Light.png
Binary file modified packages/assets/icons/Dropbox.png
Binary file modified packages/assets/icons/Encrypted-20.png
Binary file modified packages/assets/icons/Encrypted.png
Binary file modified packages/assets/icons/Encrypted_Light.png
Binary file modified packages/assets/icons/Entity.png
Binary file modified packages/assets/icons/Entity_Light.png
Binary file modified packages/assets/icons/Executable-20.png
Binary file modified packages/assets/icons/Executable.png
Binary file modified packages/assets/icons/Executable_Light.png
Binary file modified packages/assets/icons/Executable_Light_old.png
Binary file modified packages/assets/icons/Executable_old.png
Binary file modified packages/assets/icons/Face_Light.png
Binary file modified packages/assets/icons/Folder-20.png
Binary file modified packages/assets/icons/Folder-tag-xmp.png
Binary file modified packages/assets/icons/Folder.png
Binary file modified packages/assets/icons/FolderGrey.png
Binary file modified packages/assets/icons/FolderGrey_Light.png
Binary file modified packages/assets/icons/FolderNoSpace.png
Binary file modified packages/assets/icons/FolderNoSpace_Light.png
Binary file modified packages/assets/icons/Folder_Light.png
Binary file modified packages/assets/icons/Font-20.png
Binary file modified packages/assets/icons/Game.png
Binary file modified packages/assets/icons/Game_Light.png
Binary file modified packages/assets/icons/Globe.png
Binary file modified packages/assets/icons/GlobeAlt.png
Binary file modified packages/assets/icons/Globe_Light.png
Binary file modified packages/assets/icons/GoogleDrive.png
Binary file modified packages/assets/icons/HDD.png
Binary file modified packages/assets/icons/HDD_Light.png
Binary file modified packages/assets/icons/Heart.png
Binary file modified packages/assets/icons/Heart_Light.png
Binary file modified packages/assets/icons/Home.png
Binary file modified packages/assets/icons/Home_Light.png
Binary file modified packages/assets/icons/Image-20.png
Binary file modified packages/assets/icons/Image.png
Binary file modified packages/assets/icons/Image_Light.png
Binary file modified packages/assets/icons/Key-20.png
Binary file modified packages/assets/icons/Key.png
Binary file modified packages/assets/icons/Key_Light.png
Binary file modified packages/assets/icons/Keys.png
Binary file modified packages/assets/icons/Keys_Light.png
Binary file modified packages/assets/icons/Laptop.png
Binary file modified packages/assets/icons/Laptop_Light.png
Binary file modified packages/assets/icons/Link-20.png
Binary file modified packages/assets/icons/Link.png
Binary file modified packages/assets/icons/Link_Light.png
Binary file modified packages/assets/icons/Location.png
Binary file modified packages/assets/icons/LocationManaged.png
Binary file modified packages/assets/icons/LocationReplica.png
Binary file modified packages/assets/icons/Lock.png
Binary file modified packages/assets/icons/Lock_Light.png
Binary file modified packages/assets/icons/Mega.png
Binary file modified packages/assets/icons/Mesh-20.png
Binary file modified packages/assets/icons/Mesh.png
Binary file modified packages/assets/icons/Mesh_Light.png
Binary file modified packages/assets/icons/Mobile.png
Binary file modified packages/assets/icons/Mobile_Light.png
Binary file modified packages/assets/icons/MoveLocation.png
Binary file modified packages/assets/icons/MoveLocation_Light.png
Binary file modified packages/assets/icons/Movie.png
Binary file modified packages/assets/icons/Movie_Light.png
Binary file modified packages/assets/icons/NewLocation.png
Binary file modified packages/assets/icons/Node.png
Binary file modified packages/assets/icons/Node_Light.png
Binary file modified packages/assets/icons/OneDrive.png
Binary file modified packages/assets/icons/OpenStack.png
Binary file modified packages/assets/icons/PCloud.png
Binary file modified packages/assets/icons/Package-20.png
Binary file modified packages/assets/icons/Package.png
Binary file modified packages/assets/icons/Package_Light.png
Binary file modified packages/assets/icons/SD.png
Binary file modified packages/assets/icons/SD_Light.png
Binary file modified packages/assets/icons/Scrapbook.png
Binary file modified packages/assets/icons/Scrapbook_Light.png
Binary file modified packages/assets/icons/Screenshot-20.png
Binary file modified packages/assets/icons/Screenshot.png
Binary file modified packages/assets/icons/ScreenshotAlt.png
Binary file modified packages/assets/icons/Screenshot_Light.png
Binary file modified packages/assets/icons/Search.png
Binary file modified packages/assets/icons/SearchAlt.png
Binary file modified packages/assets/icons/Search_Light.png
Binary file modified packages/assets/icons/Server.png
Binary file modified packages/assets/icons/Server_Light.png
Binary file modified packages/assets/icons/SilverBox.png
Binary file modified packages/assets/icons/Spacedrop-1.png
Binary file modified packages/assets/icons/Spacedrop.png
Binary file modified packages/assets/icons/Spacedrop_Light.png
Binary file modified packages/assets/icons/Tablet.png
Binary file modified packages/assets/icons/Tablet_Light.png
Binary file modified packages/assets/icons/Tags.png
Binary file modified packages/assets/icons/Tags_Light.png
Binary file modified packages/assets/icons/Terminal.png
Binary file modified packages/assets/icons/Terminal_Light.png
Binary file modified packages/assets/icons/Text-20.png
Binary file modified packages/assets/icons/Text.png
Binary file modified packages/assets/icons/TextAlt.png
Binary file modified packages/assets/icons/TextAlt_Light.png
Binary file modified packages/assets/icons/Text_Light.png
Binary file modified packages/assets/icons/Text_txt.png
Binary file modified packages/assets/icons/TexturedMesh.png
Binary file modified packages/assets/icons/TexturedMesh_Light.png
Binary file modified packages/assets/icons/Trash.png
Binary file modified packages/assets/icons/Trash_Light.png
Binary file modified packages/assets/icons/Undefined.png
Binary file modified packages/assets/icons/Undefined_Light.png
Binary file modified packages/assets/icons/Unknown-20.png
Binary file modified packages/assets/icons/Video-20.png
Binary file modified packages/assets/icons/Video.png
Binary file modified packages/assets/icons/Video_Light.png
Binary file modified packages/assets/icons/WebPageArchive-20.png
Binary file modified packages/assets/icons/Widget-20.png
Binary file modified packages/assets/icons/Widget.png
Binary file modified packages/assets/icons/Widget_Light.png
Binary file modified packages/assets/images/AlphaBg.png
Binary file modified packages/assets/images/AlphaBg_Light.png
Binary file modified packages/assets/images/AppLogo.png
Binary file modified packages/assets/images/Ball.png
Binary file modified packages/assets/images/Dropbox.png
Binary file modified packages/assets/images/GoogleDrive.png
Binary file modified packages/assets/images/Mega.png
Binary file modified packages/assets/images/iCloud.png
10 changes: 0 additions & 10 deletions packages/assets/videos/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/config/vite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default defineConfig({
},
root: 'src',
build: {
sourcemap: true,
sourcemap: process.env.GENERATE_SOURCEMAP === 'false' ? false : true,
outDir: '../dist',
assetsDir: '.'
}
Expand Down
2 changes: 2 additions & 0 deletions scripts/tauri.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ try {
env.NODE_OPTIONS = `--max_old_space_size=4096 ${env.NODE_OPTIONS ?? ''}`
}

env.GENERATE_SOURCEMAP = 'false'

__cleanup.push(...(await patchTauri(__root, nativeDeps, targets, bundles, args)))

if (process.platform === 'darwin') {
Expand Down
2 changes: 1 addition & 1 deletion turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
"cache": false
}
},
"globalEnv": ["PORT", "NODE_ENV"]
"globalEnv": ["PORT", "NODE_ENV", "GENERATE_SOURCEMAP"]
}

0 comments on commit 81c2b8b

Please sign in to comment.