Performance fixture: real-world Rust file pair from GyulyVGC/sniffnet (src/networking/types/protocol.rs, commit 2d9c9a06482ff40b759501ba53c1caf73b80e097) that takes diff_code roughly 800ms despite a combined AST size of only 895 nodes (~25-100x slower than the log-log size/time trend fitted across the broader benchmark sample predicts). Captured via research/diff_pairs_benchmark_rust.csv; useful for regression-testing and profiling diff_code's worst-case behavior on small/medium real-world inputs.

Code view:

A painting is a person's account of this edit as text, recorded independently of the node mapping - a rendering often has several equally defensible answers where the mapping has one. Deletions and insertions carry no position on the opposite side in a painting, so that panel draws no caret for them.

Before

…lines 1–6 unchanged (6 lines)
7 /// Transmission Control Protocol
8 TCP,
9 /// User Datagram Protocol
10 UDP,
11 /// Internet Control Message Protocol
12 ICMP,
13}
14
15impl std::fmt::Display for Protocol {
16 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
17 write!(f, "{self:?}")
18 }
19}
20
21impl Protocol {
22 pub const ALL: [Protocol; 3] = [Protocol::TCP, Protocol::UDP, Protocol::ICMP];
23}
24
25#[cfg(test)]
26mod tests {
27 use super::*;
28
29 #[test]
30 fn test_protocol_display() {
31 for protocol in Protocol::ALL {
32 match protocol {
33 Protocol::TCP => assert_eq!(protocol.to_string(), "TCP"),
34 Protocol::UDP => assert_eq!(protocol.to_string(), "UDP"),
35 Protocol::ICMP => assert_eq!(protocol.to_string(), "ICMP"),
36 }
37 }
38 }
39
40 #[test]
41 fn test_all_protocols_collection() {
42 assert_eq!(Protocol::ALL.len(), 3);
43 assert_eq!(Protocol::ALL.get(0).unwrap(), &Protocol::TCP);
44 assert_eq!(Protocol::ALL.get(1).unwrap(), &Protocol::UDP);
45 assert_eq!(Protocol::ALL.get(2).unwrap(), &Protocol::ICMP);
46 }
47}
48

After

…lines 1–6 unchanged (6 lines)
7 /// Transmission Control Protocol
8 TCP,
9 /// User Datagram Protocol
10 UDP,
11 /// Internet Control Message Protocol
12 ICMP,
13 /// Address Resolution Protocol
14 ARP,
15}
16
17impl std::fmt::Display for Protocol {
18 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
19 write!(f, "{self:?}")
20 }
21}
22
23impl Protocol {
24 pub const ALL: [Protocol; 4] = [Protocol::TCP, Protocol::UDP, Protocol::ICMP, Protocol::ARP];
25}
26
27#[cfg(test)]
28mod tests {
29 use super::*;
30
31 #[test]
32 fn test_protocol_display() {
33 for protocol in Protocol::ALL {
34 match protocol {
35 Protocol::TCP => assert_eq!(protocol.to_string(), "TCP"),
36 Protocol::UDP => assert_eq!(protocol.to_string(), "UDP"),
37 Protocol::ICMP => assert_eq!(protocol.to_string(), "ICMP"),
38 Protocol::ARP => assert_eq!(protocol.to_string(), "ARP"),
39 }
40 }
41 }
42
43 #[test]
44 fn test_all_protocols_collection() {
45 assert_eq!(Protocol::ALL.len(), 3);
46 assert_eq!(Protocol::ALL.get(0).unwrap(), &Protocol::TCP);
47 assert_eq!(Protocol::ALL.get(1).unwrap(), &Protocol::UDP);
48 assert_eq!(Protocol::ALL.get(2).unwrap(), &Protocol::ICMP);
49 assert_eq!(Protocol::ALL.get(3).unwrap(), &Protocol::ARP);
50 }
51}
52

Before

source_file
line_comment
// "//"
line_comment
// "//"
outer_doc_comment_marker
/ "/"
doc_comment " Enum representing the possible observed values of protocol."...
attribute_item
# "#"
[ "["
attribute
identifier "derive"
token_tree
( "("
identifier "Debug"
, ","
identifier "Clone"
, ","
identifier "Copy"
, ","
identifier "PartialEq"
, ","
identifier "Eq"
, ","
identifier "Hash"
) ")"
] "]"
attribute_item
# "#"
[ "["
attribute
identifier "allow"
token_tree
( "("
identifier "clippy"
:: "::"
identifier "upper_case_acronyms"
) ")"
] "]"
enum_item
visibility_modifier
pub "pub"
enum "enum"
type_identifier "Protocol"
enum_variant_list
{ "{"
line_comment
// "//"
outer_doc_comment_marker
/ "/"
doc_comment " Transmission Control Protocol\n"
enum_variant
identifier "TCP"
, ","
line_comment
// "//"
outer_doc_comment_marker
/ "/"
doc_comment " User Datagram Protocol\n"
enum_variant
identifier "UDP"
, ","
line_comment
// "//"
outer_doc_comment_marker
/ "/"
doc_comment " Internet Control Message Protocol\n"
enum_variant
identifier "ICMP"
, ","
} "}"
impl_item (+60 nodes collapsed)
impl_item
impl "impl"
type_identifier "Protocol"
declaration_list
{ "{"
const_item
visibility_modifier
pub "pub"
const "const"
identifier "ALL"
: ":"
array_type
[ "["
type_identifier "Protocol"
; ";"
integer_literal "3"
] "]"
= "="
array_expression
[ "["
scoped_identifier
identifier "Protocol"
:: "::"
identifier "TCP"
, ","
scoped_identifier
identifier "Protocol"
:: "::"
identifier "UDP"
, ","
scoped_identifier
identifier "Protocol"
:: "::"
identifier "ICMP"
] "]"
; ";"
} "}"
attribute_item
# "#"
[ "["
attribute
identifier "cfg"
token_tree
( "("
identifier "test"
) ")"
] "]"
mod_item
mod "mod"
identifier "tests"
declaration_list
{ "{"
use_declaration
use "use"
use_wildcard
super "super"
:: "::"
* "*"
; ";"
attribute_item
# "#"
[ "["
attribute
identifier "test"
] "]"
function_item
fn "fn"
identifier "test_protocol_display"
parameters
( "("
) ")"
block
{ "{"
expression_statement
for_expression
for "for"
identifier "protocol"
in "in"
scoped_identifier
identifier "Protocol"
:: "::"
identifier "ALL"
block
{ "{"
expression_statement
match_expression
match "match"
identifier "protocol"
match_block
{ "{"
match_arm (+25 nodes collapsed)
match_arm (+25 nodes collapsed)
match_arm (+25 nodes collapsed)
} "}"
} "}"
} "}"
attribute_item
# "#"
[ "["
attribute
identifier "test"
] "]"
function_item
fn "fn"
identifier "test_all_protocols_collection"
parameters
( "("
) ")"
block
{ "{"
expression_statement
macro_invocation
identifier "assert_eq"
! "!"
token_tree
( "("
identifier "Protocol"
:: "::"
identifier "ALL"
. "."
identifier "len"
token_tree
( "("
) ")"
, ","
integer_literal "3"
) ")"
; ";"
expression_statement (+27 nodes collapsed)
expression_statement (+27 nodes collapsed)
expression_statement (+27 nodes collapsed)
} "}"
} "}"

After

source_file
line_comment
// "//"
line_comment
// "//"
outer_doc_comment_marker
/ "/"
doc_comment " Enum representing the possible observed values of protocol."...
attribute_item
# "#"
[ "["
attribute
identifier "derive"
token_tree
( "("
identifier "Debug"
, ","
identifier "Clone"
, ","
identifier "Copy"
, ","
identifier "PartialEq"
, ","
identifier "Eq"
, ","
identifier "Hash"
) ")"
] "]"
attribute_item
# "#"
[ "["
attribute
identifier "allow"
token_tree
( "("
identifier "clippy"
:: "::"
identifier "upper_case_acronyms"
) ")"
] "]"
enum_item
visibility_modifier
pub "pub"
enum "enum"
type_identifier "Protocol"
enum_variant_list
{ "{"
line_comment
// "//"
outer_doc_comment_marker
/ "/"
doc_comment " Transmission Control Protocol\n"
enum_variant
identifier "TCP"
, ","
line_comment
// "//"
outer_doc_comment_marker
/ "/"
doc_comment " User Datagram Protocol\n"
enum_variant
identifier "UDP"
, ","
line_comment
// "//"
outer_doc_comment_marker
/ "/"
doc_comment " Internet Control Message Protocol\n"
enum_variant
identifier "ICMP"
, ","
line_comment
// "//"
outer_doc_comment_marker
/ "/"
doc_comment " Address Resolution Protocol\n"
enum_variant
identifier "ARP"
, ","
} "}"
impl_item (+60 nodes collapsed)
impl_item
impl "impl"
type_identifier "Protocol"
declaration_list
{ "{"
const_item
visibility_modifier
pub "pub"
const "const"
identifier "ALL"
: ":"
array_type
[ "["
type_identifier "Protocol"
; ";"
integer_literal "4"
] "]"
= "="
array_expression
[ "["
scoped_identifier
identifier "Protocol"
:: "::"
identifier "TCP"
, ","
scoped_identifier
identifier "Protocol"
:: "::"
identifier "UDP"
, ","
scoped_identifier
identifier "Protocol"
:: "::"
identifier "ICMP"
, ","
scoped_identifier
identifier "Protocol"
:: "::"
identifier "ARP"
] "]"
; ";"
} "}"
attribute_item
# "#"
[ "["
attribute
identifier "cfg"
token_tree
( "("
identifier "test"
) ")"
] "]"
mod_item
mod "mod"
identifier "tests"
declaration_list
{ "{"
use_declaration
use "use"
use_wildcard
super "super"
:: "::"
* "*"
; ";"
attribute_item
# "#"
[ "["
attribute
identifier "test"
] "]"
function_item
fn "fn"
identifier "test_protocol_display"
parameters
( "("
) ")"
block
{ "{"
expression_statement
for_expression
for "for"
identifier "protocol"
in "in"
scoped_identifier
identifier "Protocol"
:: "::"
identifier "ALL"
block
{ "{"
expression_statement
match_expression
match "match"
identifier "protocol"
match_block
{ "{"
match_arm (+25 nodes collapsed)
match_arm (+25 nodes collapsed)
match_arm (+25 nodes collapsed)
match_arm
match_pattern
scoped_identifier
identifier "Protocol"
:: "::"
identifier "ARP"
=> "=>"
macro_invocation
identifier "assert_eq"
! "!"
token_tree
( "("
identifier "protocol"
. "."
identifier "to_string"
token_tree
( "("
) ")"
, ","
string_literal
" "\""
string_content "ARP"
" "\""
) ")"
, ","
} "}"
} "}"
} "}"
attribute_item
# "#"
[ "["
attribute
identifier "test"
] "]"
function_item
fn "fn"
identifier "test_all_protocols_collection"
parameters
( "("
) ")"
block
{ "{"
expression_statement
macro_invocation
identifier "assert_eq"
! "!"
token_tree
( "("
identifier "Protocol"
:: "::"
identifier "ALL"
. "."
identifier "len"
token_tree
( "("
) ")"
, ","
integer_literal "3"
) ")"
; ";"
expression_statement (+27 nodes collapsed)
expression_statement (+27 nodes collapsed)
expression_statement (+27 nodes collapsed)
expression_statement
macro_invocation
identifier "assert_eq"
! "!"
token_tree
( "("
identifier "Protocol"
:: "::"
identifier "ALL"
. "."
identifier "get"
token_tree
( "("
integer_literal "3"
) ")"
. "."
identifier "unwrap"
token_tree
( "("
) ")"
, ","
& "&"
identifier "Protocol"
:: "::"
identifier "ARP"
) ")"
; ";"
} "}"
} "}"