@@ -467,33 +467,72 @@ impl Profile {
467467        } ) 
468468    } 
469469
470-     fn  add_mapping ( & mut  self ,  mapping :  & api:: Mapping )  -> MappingId  { 
470+     fn  add_mapping ( & mut  self ,  mapping :  & api:: Mapping )  -> Option < MappingId >  { 
471+         #[ inline]  
472+         fn  is_zero_mapping ( mapping :  & api:: Mapping )  -> bool  { 
473+             // - PHP, Python, and Ruby use a mapping only as required. 
474+             // - .NET uses only the filename. 
475+             // - The native profiler uses all fields. 
476+             // We strike a balance for optimizing for the dynamic languages 
477+             // and the others by mixing branches and branchless programming. 
478+             let  filename = mapping. filename . len ( ) ; 
479+             let  build_id = mapping. build_id . len ( ) ; 
480+             if  0  != ( filename | build_id)  { 
481+                 return  false ; 
482+             } 
483+ 
484+             let  memory_start = mapping. memory_start ; 
485+             let  memory_limit = mapping. memory_limit ; 
486+             let  file_offset = mapping. file_offset ; 
487+             0  == ( memory_start | memory_limit | file_offset) 
488+         } 
489+ 
490+         if  is_zero_mapping ( mapping)  { 
491+             return  None ; 
492+         } 
493+ 
471494        let  filename = self . intern ( mapping. filename ) ; 
472495        let  build_id = self . intern ( mapping. build_id ) ; 
473496
474-         self . mappings . dedup ( Mapping  { 
497+         Some ( self . mappings . dedup ( Mapping  { 
475498            memory_start :  mapping. memory_start , 
476499            memory_limit :  mapping. memory_limit , 
477500            file_offset :  mapping. file_offset , 
478501            filename, 
479502            build_id, 
480-         } ) 
503+         } ) ) 
481504    } 
482505
483506    fn  add_string_id_mapping ( 
484507        & mut  self , 
485508        mapping :  & api:: StringIdMapping , 
486-     )  -> anyhow:: Result < MappingId >  { 
509+     )  -> anyhow:: Result < Option < MappingId > >  { 
510+         #[ inline]  
511+         fn  is_zero_mapping ( mapping :  & api:: StringIdMapping )  -> bool  { 
512+             // See the other is_zero_mapping for more info, but only Ruby is 
513+             // using this API at the moment, so we optimize for the whole 
514+             // thing being a zero representation. 
515+             let  memory_start = mapping. memory_start ; 
516+             let  memory_limit = mapping. memory_limit ; 
517+             let  file_offset = mapping. file_offset ; 
518+             let  strings = ( mapping. filename . value  | mapping. build_id . value )  as  u64 ; 
519+             0  == ( memory_start | memory_limit | file_offset | strings) 
520+         } 
521+ 
522+         if  is_zero_mapping ( mapping)  { 
523+             return  Ok ( None ) ; 
524+         } 
525+ 
487526        let  filename = self . resolve ( mapping. filename ) ?; 
488527        let  build_id = self . resolve ( mapping. build_id ) ?; 
489528
490-         Ok ( self . mappings . dedup ( Mapping  { 
529+         Ok ( Some ( self . mappings . dedup ( Mapping  { 
491530            memory_start :  mapping. memory_start , 
492531            memory_limit :  mapping. memory_limit , 
493532            file_offset :  mapping. file_offset , 
494533            filename, 
495534            build_id, 
496-         } ) ) 
535+         } ) ) ) 
497536    } 
498537
499538    fn  add_stacktrace ( & mut  self ,  locations :  Vec < LocationId > )  -> StackTraceId  { 
0 commit comments