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

add garbage collection #3094

Merged
merged 21 commits into from Jan 20, 2023
Merged

add garbage collection #3094

merged 21 commits into from Jan 20, 2023

Conversation

sokra
Copy link
Member

@sokra sokra commented Dec 20, 2022

fixes WEB-265
fixes WEB-268
fixes WEB-4
fixes WEB-359

@vercel
Copy link

vercel bot commented Dec 20, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
examples-designsystem-docs 🔄 Building (Inspect) Visit Preview Jan 19, 2023 at 4:13PM (UTC)
examples-tailwind-web 🔄 Building (Inspect) Visit Preview Jan 19, 2023 at 4:13PM (UTC)
8 Ignored Deployments
Name Status Preview Comments Updated
examples-basic-web ⬜️ Ignored (Inspect) Visit Preview Jan 19, 2023 at 4:13PM (UTC)
examples-cra-web ⬜️ Ignored (Inspect) Visit Preview Jan 19, 2023 at 4:13PM (UTC)
examples-kitchensink-blog ⬜️ Ignored (Inspect) Visit Preview Jan 19, 2023 at 4:13PM (UTC)
examples-native-web ⬜️ Ignored (Inspect) Visit Preview Jan 19, 2023 at 4:13PM (UTC)
examples-nonmonorepo ⬜️ Ignored (Inspect) Visit Preview Jan 19, 2023 at 4:13PM (UTC)
examples-svelte-web ⬜️ Ignored (Inspect) Visit Preview Jan 19, 2023 at 4:13PM (UTC)
turbo-site ⬜️ Ignored (Inspect) Visit Preview Jan 19, 2023 at 4:13PM (UTC)
turbo-vite-web ⬜️ Ignored (Inspect) Visit Preview Jan 19, 2023 at 4:13PM (UTC)

@github-actions
Copy link
Contributor

github-actions bot commented Dec 20, 2022

🟢 CI successful 🟢

Thanks

@github-actions
Copy link
Contributor

Benchmark for 7306249

Click to view benchmark
Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 8741.71µs ± 48.57µs 8840.38µs ± 89.93µs +1.13%
bench_hmr_to_commit/Turbopack RCC/1000 modules 8925.06µs ± 61.10µs 9055.79µs ± 72.85µs +1.46%
bench_hmr_to_commit/Turbopack SSR/1000 modules 8745.33µs ± 85.92µs 8799.53µs ± 83.69µs +0.62%
bench_hmr_to_eval/Turbopack CSR/1000 modules 7658.20µs ± 39.82µs 7820.10µs ± 59.00µs +2.11%
bench_hmr_to_eval/Turbopack RCC/1000 modules 7857.95µs ± 72.09µs 7994.52µs ± 70.58µs +1.74%
bench_hmr_to_eval/Turbopack SSR/1000 modules 7799.86µs ± 64.52µs 7804.61µs ± 48.74µs +0.06%
bench_hydration/Turbopack RCC/1000 modules 4038.17ms ± 37.88ms 4064.48ms ± 40.05ms +0.65%
bench_hydration/Turbopack RSC/1000 modules 3190.03ms ± 54.41ms 3241.69ms ± 35.74ms +1.62%
bench_hydration/Turbopack SSR/1000 modules 3378.15ms ± 56.51ms 3473.07ms ± 19.02ms +2.81%
bench_startup/Turbopack CSR/1000 modules 1894.35ms ± 9.59ms 1861.76ms ± 14.37ms -1.72%
bench_startup/Turbopack RCC/1000 modules 3061.44ms ± 53.10ms 3158.24ms ± 41.48ms +3.16%
bench_startup/Turbopack RSC/1000 modules 2875.30ms ± 51.11ms 2768.62ms ± 24.00ms -3.71%
bench_startup/Turbopack SSR/1000 modules 2823.62ms ± 31.82ms 2785.42ms ± 31.15ms -1.35%

@github-actions
Copy link
Contributor

github-actions bot commented Jan 9, 2023

Benchmark for 701de04

Test Base PR % Significant %
bench_hmr_to_commit/Turbopack SSR/1000 modules 8801.98µs ± 33.99µs 9145.95µs ± 119.98µs +3.91% +0.41%
bench_hmr_to_eval/Turbopack SSR/1000 modules 7758.30µs ± 48.29µs 8011.29µs ± 51.32µs +3.26% +0.68%
bench_hydration/Turbopack RCC/1000 modules 3381.07ms ± 17.41ms 3473.98ms ± 15.22ms +2.75% +0.81%
bench_hydration/Turbopack RSC/1000 modules 2856.13ms ± 9.34ms 2901.10ms ± 4.87ms +1.57% +0.58%
bench_startup/Turbopack RCC/1000 modules 2528.05ms ± 5.30ms 2571.63ms ± 5.85ms +1.72% +0.84%
bench_startup/Turbopack RSC/1000 modules 2429.94ms ± 7.08ms 2473.55ms ± 4.35ms +1.79% +0.85%
bench_startup/Turbopack SSR/1000 modules 2071.99ms ± 4.20ms 2118.18ms ± 4.79ms +2.23% +1.36%
Click to view full benchmark
Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 8789.61µs ± 86.29µs 8813.62µs ± 65.80µs +0.27%
bench_hmr_to_commit/Turbopack RCC/1000 modules 8961.81µs ± 92.33µs 9078.16µs ± 67.67µs +1.30%
bench_hmr_to_commit/Turbopack RSC/1000 modules 476.43ms ± 2.99ms 477.10ms ± 2.83ms +0.14%
bench_hmr_to_commit/Turbopack SSR/1000 modules 8801.98µs ± 33.99µs 9145.95µs ± 119.98µs +3.91% +0.41%
bench_hmr_to_eval/Turbopack CSR/1000 modules 7671.63µs ± 33.15µs 7780.92µs ± 58.09µs +1.42%
bench_hmr_to_eval/Turbopack RCC/1000 modules 7784.15µs ± 53.68µs 7834.41µs ± 72.13µs +0.65%
bench_hmr_to_eval/Turbopack SSR/1000 modules 7758.30µs ± 48.29µs 8011.29µs ± 51.32µs +3.26% +0.68%
bench_hydration/Turbopack RCC/1000 modules 3381.07ms ± 17.41ms 3473.98ms ± 15.22ms +2.75% +0.81%
bench_hydration/Turbopack RSC/1000 modules 2856.13ms ± 9.34ms 2901.10ms ± 4.87ms +1.57% +0.58%
bench_hydration/Turbopack SSR/1000 modules 2687.80ms ± 13.24ms 2683.79ms ± 8.95ms -0.15%
bench_startup/Turbopack CSR/1000 modules 1659.19ms ± 3.18ms 1663.80ms ± 4.19ms +0.28%
bench_startup/Turbopack RCC/1000 modules 2528.05ms ± 5.30ms 2571.63ms ± 5.85ms +1.72% +0.84%
bench_startup/Turbopack RSC/1000 modules 2429.94ms ± 7.08ms 2473.55ms ± 4.35ms +1.79% +0.85%
bench_startup/Turbopack SSR/1000 modules 2071.99ms ± 4.20ms 2118.18ms ± 4.79ms +2.23% +1.36%

@github-actions
Copy link
Contributor

github-actions bot commented Jan 9, 2023

Benchmark for d3506e2

Test Base PR % Significant %
bench_hmr_to_eval/Turbopack SSR/1000 modules 7727.96µs ± 59.79µs 8042.83µs ± 87.63µs +4.07% +0.26%
bench_hydration/Turbopack RCC/1000 modules 3373.75ms ± 11.45ms 3471.83ms ± 11.24ms +2.91% +1.55%
bench_hydration/Turbopack RSC/1000 modules 2854.94ms ± 7.41ms 2887.29ms ± 5.81ms +1.13% +0.21%
bench_startup/Turbopack RCC/1000 modules 2554.80ms ± 7.44ms 2608.51ms ± 8.55ms +2.10% +0.85%
bench_startup/Turbopack RSC/1000 modules 2431.60ms ± 4.42ms 2476.46ms ± 9.08ms +1.84% +0.73%
bench_startup/Turbopack SSR/1000 modules 2077.50ms ± 9.17ms 2108.72ms ± 4.98ms +1.50% +0.14%
Click to view full benchmark
Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 8701.15µs ± 60.41µs 8799.14µs ± 33.88µs +1.13%
bench_hmr_to_commit/Turbopack RCC/1000 modules 8942.93µs ± 82.05µs 9024.08µs ± 75.83µs +0.91%
bench_hmr_to_commit/Turbopack RSC/1000 modules 474.77ms ± 2.77ms 478.32ms ± 2.21ms +0.75%
bench_hmr_to_commit/Turbopack SSR/1000 modules 8818.67µs ± 45.37µs 8935.86µs ± 56.79µs +1.33%
bench_hmr_to_eval/Turbopack CSR/1000 modules 7743.02µs ± 84.48µs 7764.83µs ± 80.50µs +0.28%
bench_hmr_to_eval/Turbopack RCC/1000 modules 7752.50µs ± 72.52µs 7936.16µs ± 54.07µs +2.37%
bench_hmr_to_eval/Turbopack SSR/1000 modules 7727.96µs ± 59.79µs 8042.83µs ± 87.63µs +4.07% +0.26%
bench_hydration/Turbopack RCC/1000 modules 3373.75ms ± 11.45ms 3471.83ms ± 11.24ms +2.91% +1.55%
bench_hydration/Turbopack RSC/1000 modules 2854.94ms ± 7.41ms 2887.29ms ± 5.81ms +1.13% +0.21%
bench_hydration/Turbopack SSR/1000 modules 2690.28ms ± 13.33ms 2679.01ms ± 11.65ms -0.42%
bench_startup/Turbopack CSR/1000 modules 1659.05ms ± 3.53ms 1651.45ms ± 6.44ms -0.46%
bench_startup/Turbopack RCC/1000 modules 2554.80ms ± 7.44ms 2608.51ms ± 8.55ms +2.10% +0.85%
bench_startup/Turbopack RSC/1000 modules 2431.60ms ± 4.42ms 2476.46ms ± 9.08ms +1.84% +0.73%
bench_startup/Turbopack SSR/1000 modules 2077.50ms ± 9.17ms 2108.72ms ± 4.98ms +1.50% +0.14%

@sokra sokra marked this pull request as ready for review January 10, 2023 15:22
@ForsakenHarmony
Copy link
Member

Any chance you could add an explanation on how this works to architecture.md?

@github-actions
Copy link
Contributor

Benchmark for f1790e1

Test Base PR % Significant %
bench_hydration/Turbopack RCC/1000 modules 3280.83ms ± 10.35ms 3403.26ms ± 9.74ms +3.73% +2.49%
bench_hydration/Turbopack RSC/1000 modules 2790.63ms ± 9.04ms 2835.51ms ± 6.65ms +1.61% +0.48%
bench_startup/Turbopack RSC/1000 modules 2367.98ms ± 7.43ms 2418.25ms ± 6.46ms +2.12% +0.94%
bench_startup/Turbopack SSR/1000 modules 2037.53ms ± 6.77ms 2073.41ms ± 3.65ms +1.76% +0.73%
Click to view full benchmark
Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 7903.58µs ± 81.06µs 8056.84µs ± 51.02µs +1.94%
bench_hmr_to_commit/Turbopack RCC/1000 modules 8261.11µs ± 57.64µs 8366.61µs ± 62.76µs +1.28%
bench_hmr_to_commit/Turbopack RSC/1000 modules 468.54ms ± 1.68ms 475.53ms ± 2.62ms +1.49%
bench_hmr_to_commit/Turbopack SSR/1000 modules 8085.77µs ± 75.09µs 8344.49µs ± 110.21µs +3.20%
bench_hmr_to_eval/Turbopack CSR/1000 modules 7103.68µs ± 44.05µs 7132.00µs ± 58.08µs +0.40%
bench_hmr_to_eval/Turbopack RCC/1000 modules 7227.41µs ± 72.14µs 7310.42µs ± 65.57µs +1.15%
bench_hmr_to_eval/Turbopack SSR/1000 modules 7127.09µs ± 81.75µs 7344.41µs ± 92.27µs +3.05%
bench_hydration/Turbopack RCC/1000 modules 3280.83ms ± 10.35ms 3403.26ms ± 9.74ms +3.73% +2.49%
bench_hydration/Turbopack RSC/1000 modules 2790.63ms ± 9.04ms 2835.51ms ± 6.65ms +1.61% +0.48%
bench_hydration/Turbopack SSR/1000 modules 2616.14ms ± 11.16ms 2625.82ms ± 7.83ms +0.37%
bench_startup/Turbopack CSR/1000 modules 1618.20ms ± 3.90ms 1623.16ms ± 3.84ms +0.31%
bench_startup/Turbopack RCC/1000 modules 2490.63ms ± 5.09ms 2511.77ms ± 7.73ms +0.85%
bench_startup/Turbopack RSC/1000 modules 2367.98ms ± 7.43ms 2418.25ms ± 6.46ms +2.12% +0.94%
bench_startup/Turbopack SSR/1000 modules 2037.53ms ± 6.77ms 2073.41ms ± 3.65ms +1.76% +0.73%

Copy link
Contributor

@alexkirsz alexkirsz left a comment

Choose a reason for hiding this comment

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

This is a pretty complex change to an area of the code I'm not very familiar with.

crates/turbo-tasks-memory/src/memory_backend.rs Outdated Show resolved Hide resolved
crates/turbo-tasks-memory/src/cell.rs Outdated Show resolved Hide resolved
crates/turbo-tasks-memory/src/cell.rs Outdated Show resolved Hide resolved
let Cell::InitialValue{ content, .. } = replace(self, Cell::TrackedValueless {
dependent_tasks,
updates: 1,
}) else { unreachable!() };
Copy link
Contributor

Choose a reason for hiding this comment

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

You could also match std::mem::take(self) { ... } (replacing it with a Cell:Empty temporarily) and avoid this additional match. I think that's cleaner, and might even be compiled away.

crates/turbo-tasks-memory/src/cell.rs Outdated Show resolved Hide resolved
crates/turbo-tasks-memory/src/task.rs Outdated Show resolved Hide resolved
let min_prio_that_needs_total_duration = if active {
GcPriority::EmptyCells {
total_compute_duration: to_exp_u8(last_duration.as_millis() as u64),
age: Reverse(age),
Copy link
Contributor

Choose a reason for hiding this comment

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

Concerns of the Gc should not leak to this module, i.e. there should be a empty_cells(duration: Duration, age: Duration) that creates this enum variant. It shouldn't have to deal with Reverse and to_exp_u8.

stats: &mut GcStats,
backend: &MemoryBackend,
turbo_tasks: &dyn TurboTasksBackendApi,
) -> Option<GcPriority> {
Copy link
Contributor

Choose a reason for hiding this comment

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

This function is huge. Can it be split into smaller, more digestible parts?

crates/turbo-tasks-memory/src/task/stats.rs Outdated Show resolved Hide resolved
)
#[allow(clippy::blocks_in_if_conditions)]
while CURRENT_TASK_STATE
.scope(Default::default(), async {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this return a ControlFlow instead, just to make it clear that we're breaking or continuing a loop?

Copy link
Contributor

@jridgewell jridgewell left a comment

Choose a reason for hiding this comment

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

I really can't track the code paths in manager.rs, and I haven't even started task.rs yet.

@@ -452,12 +511,16 @@ impl TaskScopeState {
self.decrement_active_by(1, more_jobs);
}
/// decrement the active counter, returns list of child scopes that need to
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Out of date comment?

event: Event,
}

impl PriorityPair {
Copy link
Contributor

Choose a reason for hiding this comment

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

Needs docs. It wasn't clear to me until I read memory_backend that the high priority items use before/after hooks and low priority use callback styles.

}

pub async fn run_low<T, F: Future<Output = T>>(&self, f: F) -> T {
while self.current.load(Ordering::Acquire) != 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment: Why not just return a future that readies after the state is 0?

pub async fn run_low<T, F: Future<Output = T>>(&self, f: F) -> T {
while self.current.load(Ordering::Acquire) != 0 {
let listener = self.event.listen();
if self.current.load(Ordering::Acquire) != 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment: Can you explain why you double check?

crates/turbo-tasks-memory/src/cell.rs Show resolved Hide resolved
if scope.state.lock().decrement_active_by(count, &mut queue) {
self.gc_queue.task_might_become_inactive(task_id);
}
});
while let Some(scope) = queue.pop() {
self.with_scope(scope, |scope| {
scope.state.lock().decrement_active_by(count, &mut queue)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could the queued child tasks also become inactive?

crates/turbo-tasks-memory/src/memory_backend.rs Outdated Show resolved Hide resolved
crates/turbo-tasks-memory/src/gc.rs Show resolved Hide resolved
@github-actions
Copy link
Contributor

Benchmark for d63034e

Test Base PR % Significant %
bench_hmr_to_eval/Turbopack SSR/1000 modules 7924.41µs ± 69.01µs 8505.79µs ± 118.58µs +7.34% +2.56%
bench_hydration/Turbopack RCC/1000 modules 3718.13ms ± 15.74ms 3817.45ms ± 19.60ms +2.67% +0.76%
bench_startup/Turbopack CSR/1000 modules 1758.28ms ± 5.91ms 1908.53ms ± 13.66ms +8.55% +6.28%
bench_startup/Turbopack RSC/1000 modules 2712.85ms ± 17.04ms 2782.39ms ± 14.87ms +2.56% +0.21%
Click to view full benchmark
Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 8921.36µs ± 51.39µs 9026.99µs ± 60.90µs +1.18%
bench_hmr_to_commit/Turbopack RCC/1000 modules 9210.75µs ± 77.01µs 9299.02µs ± 71.09µs +0.96%
bench_hmr_to_commit/Turbopack RSC/1000 modules 496.19ms ± 2.99ms 496.64ms ± 4.63ms +0.09%
bench_hmr_to_commit/Turbopack SSR/1000 modules 8975.72µs ± 76.85µs 9096.46µs ± 89.30µs +1.35%
bench_hmr_to_eval/Turbopack CSR/1000 modules 8163.99µs ± 65.94µs 8322.32µs ± 79.23µs +1.94%
bench_hmr_to_eval/Turbopack RCC/1000 modules 8025.54µs ± 73.38µs 8063.39µs ± 63.83µs +0.47%
bench_hmr_to_eval/Turbopack SSR/1000 modules 7924.41µs ± 69.01µs 8505.79µs ± 118.58µs +7.34% +2.56%
bench_hydration/Turbopack RCC/1000 modules 3718.13ms ± 15.74ms 3817.45ms ± 19.60ms +2.67% +0.76%
bench_hydration/Turbopack RSC/1000 modules 3225.66ms ± 11.55ms 3275.54ms ± 18.02ms +1.55%
bench_hydration/Turbopack SSR/1000 modules 3032.37ms ± 21.00ms 3032.76ms ± 17.06ms +0.01%
bench_startup/Turbopack CSR/1000 modules 1758.28ms ± 5.91ms 1908.53ms ± 13.66ms +8.55% +6.28%
bench_startup/Turbopack RCC/1000 modules 2956.29ms ± 30.04ms 2963.40ms ± 22.76ms +0.24%
bench_startup/Turbopack RSC/1000 modules 2712.85ms ± 17.04ms 2782.39ms ± 14.87ms +2.56% +0.21%
bench_startup/Turbopack SSR/1000 modules 2304.20ms ± 11.55ms 2350.98ms ± 21.22ms +2.03%

@github-actions
Copy link
Contributor

Benchmark for 6ba7905

Test Base PR % Significant %
bench_hydration/Turbopack RCC/1000 modules 3337.96ms ± 8.47ms 3393.39ms ± 10.40ms +1.66% +0.53%
Click to view full benchmark
Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 8793.42µs ± 49.96µs 8892.03µs ± 90.22µs +1.12%
bench_hmr_to_commit/Turbopack RCC/1000 modules 9022.62µs ± 72.91µs 9041.01µs ± 67.07µs +0.20%
bench_hmr_to_commit/Turbopack RSC/1000 modules 448.26ms ± 1.36ms 452.81ms ± 1.95ms +1.01%
bench_hmr_to_commit/Turbopack SSR/1000 modules 8971.00µs ± 47.88µs 9015.43µs ± 103.77µs +0.50%
bench_hmr_to_eval/Turbopack CSR/1000 modules 7743.43µs ± 83.97µs 7817.36µs ± 44.32µs +0.95%
bench_hmr_to_eval/Turbopack RCC/1000 modules 8022.19µs ± 70.76µs 7974.34µs ± 31.98µs -0.60%
bench_hmr_to_eval/Turbopack SSR/1000 modules 7913.64µs ± 66.60µs 7988.90µs ± 76.07µs +0.95%
bench_hydration/Turbopack RCC/1000 modules 3337.96ms ± 8.47ms 3393.39ms ± 10.40ms +1.66% +0.53%
bench_hydration/Turbopack RSC/1000 modules 2840.16ms ± 10.58ms 2847.89ms ± 8.85ms +0.27%
bench_hydration/Turbopack SSR/1000 modules 2649.86ms ± 8.04ms 2636.81ms ± 8.73ms -0.49%
bench_startup/Turbopack CSR/1000 modules 1642.44ms ± 5.24ms 1638.84ms ± 6.62ms -0.22%
bench_startup/Turbopack RCC/1000 modules 2491.02ms ± 5.34ms 2513.13ms ± 6.85ms +0.89%
bench_startup/Turbopack RSC/1000 modules 2380.96ms ± 7.85ms 2405.59ms ± 6.53ms +1.03%
bench_startup/Turbopack SSR/1000 modules 2053.54ms ± 4.98ms 2063.93ms ± 4.89ms +0.51%

@jridgewell jridgewell changed the title add garbagge collection add garbage collection Jan 19, 2023
@sokra sokra merged commit c9d8bc9 into main Jan 20, 2023
@sokra sokra deleted the memory/gc branch January 20, 2023 09:16
jridgewell pushed a commit to vercel/next.js that referenced this pull request Mar 10, 2023
sokra added a commit to vercel/next.js that referenced this pull request Mar 13, 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.

None yet

4 participants