Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions test/e2e/favicon-short-circuit/favicon-short-circuit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ describe('favicon-short-circuit', () => {
expect(res.status).toBe(404)
expect(res.headers.get('content-type')).toBe('text/html; charset=utf-8')

// Expect we got the right body.
// Expect we got HTML as text (with a non-empty body unlike in dev) and also not binary data
const html = await res.text()
expect(html).toContain('<html>')
expect(html).toContain('<html')
})
}
})
17 changes: 1 addition & 16 deletions test/production/deterministic-build/deployment-id.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,18 @@ async function readFiles(next: NextInstance) {
)
}

// TODO static/* browser chunks are content hashed and have the deployment id inlined
const IGNORE_NAME = /^static\/chunks\//
const IGNORE_CONTENT = new RegExp(
[
// TODO These contain content-hashed browser chunk urls (and/or the deployment id query param)
'page_client-reference-manifest\\.js',
'build-manifest\\.json',
// TODO This contains
// - content-hashed browser chunk urls (and/or the deployment id query param)
// - browser chunk urls inside of a folder named after the build id
'middleware-build-manifest\\.js',
// TODO this contains "env": { "__NEXT_BUILD_ID": "taBOOu8Znzobe4G7wEG_i",
'middleware-manifest\\.json',
// TODO this contains the build id
'BUILD_ID',
// TODO this contains the build id: "/pages-static-gsp": { "dataRoute": "/_next/data/V7oVUAlS1LiV5CqrtpkAL/pages-static-gsp.json",
'prerender-manifest\\.json',
// TODO These contain (but are not deployed to the serverless function itself)
// - content-hashed browser chunk urls
// - the build id
// TODO These contain the build id (but are not deployed to the serverless function itself)
'.*\\.html',
'.*\\.rsc',
// These are not critical, as they aren't deployed to the serverless function itself
'_buildManifest\\.js',
'client-build-manifest\\.json',
'fallback-build-manifest\\.json',
'routes-manifest\\.json',
Expand Down Expand Up @@ -98,9 +86,6 @@ const IGNORE_CONTENT = new RegExp(
await next.build()
let run2 = await readFiles(next)

run1 = run1.filter(([f, _]) => !IGNORE_NAME.test(f))
run2 = run2.filter(([f, _]) => !IGNORE_NAME.test(f))

// First, compare file names
let run1FileNames = run1.map(([f, _]) => f)
let run2FileNames = run2.map(([f, _]) => f)
Expand Down
5 changes: 4 additions & 1 deletion turbopack/crates/turbo-tasks-auto-hash-map/src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,9 @@ impl<K: Eq + Hash, V, H: BuildHasher + Default, const I: usize> AutoMap<K, V, H,
match self {
AutoMap::List(list) => {
if list.capacity() > list.len() * 3 {
list.shrink_to_fit();
// You need to call "grow" to shrink a SmallVec to a specific capacity
// There is no Vec::shrink_to() equivalent for SmallVec
list.grow(list.len().next_power_of_two());
}
}
AutoMap::Map(map) => {
Expand All @@ -280,6 +282,7 @@ impl<K: Eq + Hash, V, H: BuildHasher + Default, const I: usize> AutoMap<K, V, H,
list.extend(map.drain());
*self = AutoMap::List(list);
} else if map.capacity() > map.len() * 3 {
// HashMaps will always have a capacity that is a power of two
map.shrink_to_fit();
}
}
Expand Down
4 changes: 4 additions & 0 deletions turbopack/crates/turbo-tasks-backend/src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2580,6 +2580,10 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
task.shrink_to_fit(CachedDataItemType::CellDependency);
task.shrink_to_fit(CachedDataItemType::OutputDependency);
task.shrink_to_fit(CachedDataItemType::CollectiblesDependency);
task.shrink_to_fit(CachedDataItemType::OutdatedOutputDependency);
task.shrink_to_fit(CachedDataItemType::OutdatedCellDependency);
task.shrink_to_fit(CachedDataItemType::OutdatedCollectiblesDependency);
task.shrink_to_fit(CachedDataItemType::OutdatedCollectible);

drop(task);
}
Expand Down
17 changes: 11 additions & 6 deletions turbopack/crates/turbo-tasks/src/priority_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,7 @@ impl<
) -> Option<(E::Future, Option<Sender<()>>)> {
let mut queue = self.queue.lock();
if let Some(heap_item) = queue.pop() {
if queue.len() * 2 + 16 < queue.capacity() {
queue.shrink_to_fit();
}
shrink_amortized(&mut queue);
drop(queue);
let tx = heap_item.tx;
Some((
Expand All @@ -198,9 +196,7 @@ impl<
) -> bool {
let mut queue = self.queue.lock();
if let Some(heap_item) = queue.pop() {
if queue.len() * 2 + 16 < queue.capacity() {
queue.shrink_to_fit();
}
shrink_amortized(&mut queue);
drop(queue);
let tx = heap_item.tx;
let new_future =
Expand All @@ -218,6 +214,15 @@ impl<
}
}

fn shrink_amortized<P, T>(queue: &mut BinaryHeap<HeapItem<P, T>>) {
// Amortized shrinking of the queue, but with a lower threshold to avoid
// frequent reallocations when the queue is small.
if queue.capacity() > queue.len() * 3 && queue.capacity() > 128 {
let new_capacity = queue.len().next_power_of_two().max(128);
queue.shrink_to(new_capacity);
}
}

#[derive(Debug)]
enum WorkerState {
UnfinishedFuture,
Expand Down
Loading