-
-
Notifications
You must be signed in to change notification settings - Fork 148
Bladeacer cpu usage fix #621
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
Open
bladeacer
wants to merge
16
commits into
SurgeDM:main
Choose a base branch
from
bladeacer:bladeacer-cpu-usage-fix
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
0e86fee
feat: snapshot caching on BitmapTracker
bladeacer c8f14e2
fix: More perf optimisations
bladeacer 12bafd9
feat: Caching for more panes
bladeacer d97102c
feat: TUI join optimisation
bladeacer 9e72d73
feat: added TUI perf job to CI
bladeacer b0803a7
feat: Added modal golden fixtures
bladeacer 18e6af9
feat: More CI improvements
bladeacer c37bd58
feat: FilePicker modal golden
bladeacer 8086e0e
feat: Development docs
bladeacer 74018d8
feat; Comparison scripts
bladeacer 40218b4
feat: Replaced __future__ annotations with typing for Python scripts
bladeacer d60856a
fix: Fix CI issues
bladeacer 577e8cc
fix: Added proposed CodeRabbit fixes
bladeacer ff6b741
feat: CI fixes
bladeacer 27cf370
feat: TUI render and other proposed fixes
bladeacer bf6c9ba
fix: make TUI render caches reusable
SuperCoolPencil File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,49 +1,76 @@ | ||
| # Contributing | ||
|
|
||
| Thanks for checking out Surge. We are very open to contributions and happy to review PRs. | ||
| Thanks for contributing to Surge. Start with the [Development Guide](docs/DEVELOPMENT.md) for prerequisites and the complete local workflow. | ||
|
|
||
| This is intentionally short. If you see something that can be better, open a PR. | ||
| ## Quick start | ||
|
|
||
| ## Quick Codebase Map | ||
| From the repository root: | ||
|
|
||
| - `cmd/`: CLI commands and startup wiring (`surge get`, `surge server`, etc.). | ||
| - `internal/core/`: service layer (`LocalDownloadService`) that orchestrates add/pause/resume/delete/list. | ||
| - `internal/download/`: high-level download flow (`RunDownload`) and worker-pool lifecycle. | ||
| - `internal/engine/`: low-level engine code. | ||
| - `internal/engine/probe.go`: probe logic (range support, metadata, mirror probing). | ||
| - `internal/engine/concurrent/`: concurrent HTTP downloader and worker/retry/failover logic. | ||
| - `internal/engine/single/`: single-connection HTTP downloader fallback. | ||
| - `internal/engine/state/`: Gob-backed file persistence for paused/history downloads. | ||
| - `internal/tui/`: terminal UI models, update loop, views. | ||
| - `internal/testutil/`: mock HTTP servers and test helpers. | ||
| ```bash | ||
| go mod download | ||
| go test ./... | ||
| go test -race ./internal/... | ||
| ``` | ||
|
|
||
| The core Go workflow uses the dependencies pinned in `go.mod` and `go.sum`. The Python performance scripts require Python 3.8+ but only use the standard library, so no pip install is needed. Browser-extension work additionally requires Node.js 22+ and `npm ci` in `extension/`; ShellCheck and actionlint are optional locally and are enforced by CI. | ||
|
|
||
| If you are looking for networking behavior, start here: | ||
| For local configuration isolation while running the TUI or server: | ||
|
|
||
| ```bash | ||
| XDG_CONFIG_HOME="$(mktemp -d)" XDG_CACHE_HOME="$(mktemp -d)" go run . | ||
| ``` | ||
|
|
||
| 1. `internal/engine/probe.go` | ||
| 2. `internal/engine/concurrent/` | ||
| 3. `internal/engine/single/` | ||
| ## Codebase map | ||
|
|
||
| ## Run Tests | ||
| - `cmd/`: Cobra commands, startup wiring, and CLI/server entry points. | ||
| - `internal/orchestrator/`: lifecycle management, enqueueing, pause/resume, and event coordination. | ||
| - `internal/scheduler/`: queued/active download scheduling, rate-limit pools, and shutdown behavior. | ||
| - `internal/strategy/concurrent/`: ranged, mirrored, retried, hedged, and health-monitored downloads. | ||
| - `internal/strategy/single/`: single-connection fallback downloads and throttled streaming. | ||
| - `internal/probe/`: server capability and metadata probing. | ||
| - `internal/transport/`: network pools, host penalties, and byte rate limiters. | ||
| - `internal/progress/`: live download state, chunk maps, and progress aggregation. | ||
| - `internal/store/`: persisted download and resume state. | ||
| - `internal/tui/`: Bubble Tea model/update loop, dashboard panes, modal components, and render tests. | ||
| - `internal/testutil/`: mock servers, temporary directories, and test helpers. | ||
| - `extension/`: WXT/Solid browser extension source and tests. | ||
|
|
||
| From repo root: | ||
| ## Focused checks | ||
|
|
||
| Use focused package tests while iterating: | ||
|
|
||
| ```bash | ||
| go test ./... | ||
| go test ./internal/tui ./internal/tui/components -count=1 | ||
| go test ./internal/strategy/concurrent -count=1 | ||
| go test ./internal/strategy/single -count=1 | ||
| go test ./internal/transport -run 'RateLimiter|HostRateLimiter' -count=1 | ||
| ``` | ||
|
|
||
| For TUI rendering changes, also run the opt-in budgets and rendering benchmarks: | ||
|
|
||
| ```bash | ||
| GOMAXPROCS=2 SURGE_PERF_BUDGET=1 \ | ||
| go test ./internal/tui -run '^TestTUI.*RenderPerfBudget$' -count=3 -v | ||
| go test ./internal/tui -run '^$' \ | ||
| -bench '^BenchmarkCPU_(FullView_Old|FullView_New|DashboardPanes_Cached)$' \ | ||
| -benchmem -count=3 -benchtime=500ms | ||
| ``` | ||
|
|
||
| Useful focused runs: | ||
| For workflow or shell changes: | ||
|
|
||
| ```bash | ||
| go test ./internal/engine/concurrent -run TestConcurrentDownloader_SwitchOn429 -count=1 | ||
| go test ./internal/download -run TestIntegration_PauseResume -count=1 | ||
| go test ./internal/tui -count=1 | ||
| find scripts -type f -name '*.sh' -print0 | xargs -0 -r shellcheck | ||
| go run github.com/rhysd/actionlint/cmd/actionlint@v1.7.7 | ||
| ``` | ||
|
|
||
| ## PR Expectations | ||
| ## Pull requests | ||
|
|
||
| - Keep PRs focused and readable. | ||
| - Add or update tests for behavior changes. | ||
| - Run `go test ./...` before opening/updating the PR. | ||
| - If behavior or CLI usage changes, update docs (`README.md` or `docs/`). | ||
| - Keep each PR focused and explain the user-visible motivation. | ||
| - Add regression tests for behavior changes and golden tests for terminal rendering changes. | ||
| - Preserve existing platform behavior; avoid assuming Linux unless the code path is platform-specific. | ||
| - Run `gofmt` on changed Go files. | ||
| - Run `go test ./...` and, for core changes, `go test -race ./internal/...`. | ||
| - Update `README.md`, `docs/`, or CLI help when setup, behavior, or user-facing commands change. | ||
| - Do not commit generated binaries, profiles, perf reports, temporary config directories, or downloaded artifacts. | ||
|
|
||
| That is it. If you are unsure about approach, open a draft PR early and we can iterate on it together. | ||
| CI runs the full race-tested Go suite across the supported operating systems, TUI performance budgets when relevant files change, ShellCheck, actionlint, and extension checks when extension files change. |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.