@@ -58,20 +58,19 @@ const SCHEMA_SERIALIZE_SPAN: &str = "asn1.schema.serialize";
5858/// This function is marked `#[inline]` for minimal overhead in performance-critical
5959/// encoding paths. The span creation is optimized for low-latency trading systems.
6060/// Common encoding rules (BER, DER, OER, PER, XER, JER) use static strings to avoid
61- /// heap allocation, with format!() fallback only for rare unknown rules.
61+ /// heap allocation, with fallback to generic span name for rare unknown rules.
6262#[ inline]
6363pub fn encoding_span ( encoding_rule : & str , _message_type : & str ) -> Span {
64- let span_name = match encoding_rule {
65- "BER" => ENCODE_BER_SPAN ,
66- "DER" => ENCODE_DER_SPAN ,
67- "OER" => ENCODE_OER_SPAN ,
68- "PER" => ENCODE_PER_SPAN ,
69- "XER" => ENCODE_XER_SPAN ,
70- "JER" => ENCODE_JER_SPAN ,
71- // Fall back to format!() for unknown encoding rules (rare case)
72- _ => return Span :: enter_with_local_parent ( format ! ( "asn1.encode.{encoding_rule}" ) ) ,
73- } ;
74- Span :: enter_with_local_parent ( span_name)
64+ match encoding_rule {
65+ "BER" => Span :: enter_with_local_parent ( ENCODE_BER_SPAN ) ,
66+ "DER" => Span :: enter_with_local_parent ( ENCODE_DER_SPAN ) ,
67+ "OER" => Span :: enter_with_local_parent ( ENCODE_OER_SPAN ) ,
68+ "PER" => Span :: enter_with_local_parent ( ENCODE_PER_SPAN ) ,
69+ "XER" => Span :: enter_with_local_parent ( ENCODE_XER_SPAN ) ,
70+ "JER" => Span :: enter_with_local_parent ( ENCODE_JER_SPAN ) ,
71+ // Use generic span name for unknown encoding rules (rare case) to avoid heap allocation
72+ _ => Span :: enter_with_local_parent ( "asn1.encode.unknown" ) ,
73+ }
7574}
7675
7776/// Creates a new span for decoding operations.
@@ -106,20 +105,19 @@ pub fn encoding_span(encoding_rule: &str, _message_type: &str) -> Span {
106105/// This function is marked `#[inline]` for minimal overhead in performance-critical
107106/// decoding paths. The span creation is optimized for low-latency message processing.
108107/// Common encoding rules (BER, DER, OER, PER, XER, JER) use static strings to avoid
109- /// heap allocation, with format!() fallback only for rare unknown rules.
108+ /// heap allocation, with fallback to generic span name for rare unknown rules.
110109#[ inline]
111110pub fn decoding_span ( encoding_rule : & str , _data_size : usize ) -> Span {
112- let span_name = match encoding_rule {
113- "BER" => DECODE_BER_SPAN ,
114- "DER" => DECODE_DER_SPAN ,
115- "OER" => DECODE_OER_SPAN ,
116- "PER" => DECODE_PER_SPAN ,
117- "XER" => DECODE_XER_SPAN ,
118- "JER" => DECODE_JER_SPAN ,
119- // Fall back to format!() for unknown encoding rules (rare case)
120- _ => return Span :: enter_with_local_parent ( format ! ( "asn1.decode.{encoding_rule}" ) ) ,
121- } ;
122- Span :: enter_with_local_parent ( span_name)
111+ match encoding_rule {
112+ "BER" => Span :: enter_with_local_parent ( DECODE_BER_SPAN ) ,
113+ "DER" => Span :: enter_with_local_parent ( DECODE_DER_SPAN ) ,
114+ "OER" => Span :: enter_with_local_parent ( DECODE_OER_SPAN ) ,
115+ "PER" => Span :: enter_with_local_parent ( DECODE_PER_SPAN ) ,
116+ "XER" => Span :: enter_with_local_parent ( DECODE_XER_SPAN ) ,
117+ "JER" => Span :: enter_with_local_parent ( DECODE_JER_SPAN ) ,
118+ // Use generic span name for unknown encoding rules (rare case) to avoid heap allocation
119+ _ => Span :: enter_with_local_parent ( "asn1.decode.unknown" ) ,
120+ }
123121}
124122
125123/// Creates a new span for schema operations.
@@ -164,20 +162,19 @@ pub fn decoding_span(encoding_rule: &str, _data_size: usize) -> Span {
164162/// can be performance-critical in message processing pipelines, especially when
165163/// validating incoming messages in real-time trading systems.
166164/// Common operations (validate, lookup, compile, transform, parse, serialize) use
167- /// static strings to avoid heap allocation, with format!() fallback only for rare unknown operations.
165+ /// static strings to avoid heap allocation, with fallback to generic span name for rare unknown operations.
168166#[ inline]
169167pub fn schema_span ( operation : & str ) -> Span {
170- let span_name = match operation {
171- "validate" => SCHEMA_VALIDATE_SPAN ,
172- "lookup" => SCHEMA_LOOKUP_SPAN ,
173- "compile" => SCHEMA_COMPILE_SPAN ,
174- "transform" => SCHEMA_TRANSFORM_SPAN ,
175- "parse" => SCHEMA_PARSE_SPAN ,
176- "serialize" => SCHEMA_SERIALIZE_SPAN ,
177- // Fall back to format!() for unknown operations (rare case)
178- _ => return Span :: enter_with_local_parent ( format ! ( "asn1.schema.{operation}" ) ) ,
179- } ;
180- Span :: enter_with_local_parent ( span_name)
168+ match operation {
169+ "validate" => Span :: enter_with_local_parent ( SCHEMA_VALIDATE_SPAN ) ,
170+ "lookup" => Span :: enter_with_local_parent ( SCHEMA_LOOKUP_SPAN ) ,
171+ "compile" => Span :: enter_with_local_parent ( SCHEMA_COMPILE_SPAN ) ,
172+ "transform" => Span :: enter_with_local_parent ( SCHEMA_TRANSFORM_SPAN ) ,
173+ "parse" => Span :: enter_with_local_parent ( SCHEMA_PARSE_SPAN ) ,
174+ "serialize" => Span :: enter_with_local_parent ( SCHEMA_SERIALIZE_SPAN ) ,
175+ // Use generic span name for unknown operations (rare case) to avoid heap allocation
176+ _ => Span :: enter_with_local_parent ( "asn1.schema.unknown" ) ,
177+ }
181178}
182179
183180/// Measures encoding performance metrics.
0 commit comments