Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
48f5f34a
Unverified
Commit
48f5f34a
authored
Jun 04, 2026
by
Andrew Imm
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Trace viewer: store span IDs in a Vec instead of a HashMap
parent
ceff7268
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
4 deletions
+48
-4
turbopack.rs
...ack/crates/turbopack-trace-server/src/reader/turbopack.rs
+48
-4
No files found.
turbopack/crates/turbopack-trace-server/src/reader/turbopack.rs
View file @
48f5f34a
...
@@ -67,9 +67,53 @@ enum InternalRowType {
...
@@ -67,9 +67,53 @@ enum InternalRowType {
},
},
}
}
/// Dense map from external span id to `SpanIndex`.
///
/// The turbopack tracing layer assigns span ids sequentially starting at 1, so
/// the key space is effectively contiguous (measured density ≈ 1.0 on real
/// traces). Indexing a `Vec` beats hashing an `FxHashMap` on the ingest hot path
/// and uses less memory; `Option<SpanIndex>` is a single `usize` thanks to the
/// `NonZeroUsize` niche. Ids that have not been seen yet read back as `None`,
/// matching the old `HashMap::get` semantics relied on for out-of-order parents.
#[derive(Default)]
struct
DenseIdMap
{
vec
:
Vec
<
Option
<
SpanIndex
>>
,
count
:
usize
,
}
impl
DenseIdMap
{
fn
with_capacity
(
cap
:
usize
)
->
Self
{
Self
{
vec
:
Vec
::
with_capacity
(
cap
),
count
:
0
,
}
}
#[inline]
fn
get
(
&
self
,
id
:
u64
)
->
Option
<
SpanIndex
>
{
self
.vec
.get
(
id
as
usize
)
.copied
()
.flatten
()
}
#[inline]
fn
insert
(
&
mut
self
,
id
:
u64
,
index
:
SpanIndex
)
{
let
i
=
id
as
usize
;
if
i
>=
self
.vec
.len
()
{
self
.vec
.resize
(
i
+
1
,
None
);
}
if
self
.vec
[
i
]
.is_none
()
{
self
.count
+=
1
;
}
self
.vec
[
i
]
=
Some
(
index
);
}
fn
len
(
&
self
)
->
usize
{
self
.count
}
}
pub
struct
TurbopackFormat
{
pub
struct
TurbopackFormat
{
store
:
Arc
<
StoreContainer
>
,
store
:
Arc
<
StoreContainer
>
,
id_mapping
:
FxHashMap
<
u64
,
SpanIndex
>
,
id_mapping
:
DenseIdMap
,
dropped_ids
:
FxHashSet
<
u64
>
,
dropped_ids
:
FxHashSet
<
u64
>
,
remaining_ids_to_drop
:
usize
,
remaining_ids_to_drop
:
usize
,
queued_rows
:
FxHashMap
<
u64
,
Vec
<
InternalRow
>>
,
queued_rows
:
FxHashMap
<
u64
,
Vec
<
InternalRow
>>
,
...
@@ -88,7 +132,7 @@ impl TurbopackFormat {
...
@@ -88,7 +132,7 @@ impl TurbopackFormat {
.unwrap_or_default
();
.unwrap_or_default
();
Self
{
Self
{
store
,
store
,
id_mapping
:
FxHashMap
::
with_capacity_and_hasher
(
131
_072
,
Default
::
default
()
),
id_mapping
:
DenseIdMap
::
with_capacity
(
131
_072
),
dropped_ids
:
FxHashSet
::
with_capacity_and_hasher
(
drop_ids
,
Default
::
default
()),
dropped_ids
:
FxHashSet
::
with_capacity_and_hasher
(
drop_ids
,
Default
::
default
()),
remaining_ids_to_drop
:
drop_ids
,
remaining_ids_to_drop
:
drop_ids
,
queued_rows
:
FxHashMap
::
with_capacity_and_hasher
(
1
_024
,
Default
::
default
()),
queued_rows
:
FxHashMap
::
with_capacity_and_hasher
(
1
_024
,
Default
::
default
()),
...
@@ -366,8 +410,8 @@ impl TurbopackFormat {
...
@@ -366,8 +410,8 @@ impl TurbopackFormat {
{
{
return
;
return
;
}
}
if
let
Some
(
i
d
)
=
self
.id_mapping
.get
(
&
id
)
{
if
let
Some
(
i
ndex
)
=
self
.id_mapping
.get
(
id
)
{
Some
(
*
id
)
Some
(
index
)
}
else
{
}
else
{
// Parent hasn't been seen yet; queue this row to be processed
// Parent hasn't been seen yet; queue this row to be processed
// when the parent arrives. The row is already lifetime-free
// when the parent arrives. The row is already lifetime-free
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment