Skip to content

Commit 8679a04

Browse files
authored
write: use FNV hash in more places (#830)
The abbreviations change noticeably improved performance. The other changes were too small to be sure, but I think it's probably better to switch them all.
1 parent e024ccc commit 8679a04

File tree

8 files changed

+32
-34
lines changed

8 files changed

+32
-34
lines changed

src/write/abbrev.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
use alloc::vec::Vec;
2-
use indexmap::IndexSet;
32
use std::ops::{Deref, DerefMut};
43

54
use crate::common::{DebugAbbrevOffset, SectionId};
65
use crate::constants;
7-
use crate::write::{Result, Section, Writer};
6+
use crate::write::{FnvIndexSet, Result, Section, Writer};
87

98
/// A table of abbreviations that will be stored in a `.debug_abbrev` section.
109
// Requirements:
@@ -13,7 +12,7 @@ use crate::write::{Result, Section, Writer};
1312
// - inserting a duplicate returns the code of the existing value
1413
#[derive(Debug, Default)]
1514
pub(crate) struct AbbreviationTable {
16-
abbrevs: IndexSet<Abbreviation>,
15+
abbrevs: FnvIndexSet<Abbreviation>,
1716
}
1817

1918
impl AbbreviationTable {

src/write/cfi.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
use alloc::vec::Vec;
2-
use indexmap::IndexSet;
32
use std::ops::{Deref, DerefMut};
43

54
use crate::common::{DebugFrameOffset, EhFrameOffset, Encoding, Format, Register, SectionId};
65
use crate::constants;
7-
use crate::write::{Address, BaseId, Error, Expression, Result, Section, Writer};
6+
use crate::write::{Address, BaseId, Error, Expression, FnvIndexSet, Result, Section, Writer};
87

98
define_section!(
109
DebugFrame,
@@ -22,7 +21,7 @@ pub struct FrameTable {
2221
/// Base id for CIEs.
2322
base_id: BaseId,
2423
/// The common information entries.
25-
cies: IndexSet<CommonInformationEntry>,
24+
cies: FnvIndexSet<CommonInformationEntry>,
2625
/// The frame description entries.
2726
fdes: Vec<(CieId, FrameDescriptionEntry)>,
2827
}
@@ -597,7 +596,7 @@ pub(crate) mod convert {
597596
use super::*;
598597
use crate::read::{self, Reader};
599598
use crate::write::{ConvertError, ConvertResult, NoConvertDebugInfoRef};
600-
use fnv::FnvHashMap as HashMap;
599+
use fnv::FnvHashMap;
601600
use std::collections::hash_map;
602601

603602
impl FrameTable {
@@ -621,7 +620,7 @@ pub(crate) mod convert {
621620

622621
let mut frame_table = FrameTable::default();
623622

624-
let mut cie_ids = HashMap::default();
623+
let mut cie_ids = FnvHashMap::default();
625624
let mut entries = frame.entries(&bases);
626625
while let Some(entry) = entries.next()? {
627626
let partial = match entry {

src/write/line.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use alloc::vec::Vec;
2-
use indexmap::{IndexMap, IndexSet};
32
use std::ops::{Deref, DerefMut};
43

54
use crate::common::{DebugLineOffset, Encoding, Format, LineEncoding, SectionId};
65
use crate::constants;
76
use crate::leb128;
87
use crate::write::{
9-
Address, Error, LineStringId, LineStringTable, Result, Section, StringId, StringTable, Writer,
8+
Address, Error, FnvIndexMap, FnvIndexSet, LineStringId, LineStringTable, Result, Section,
9+
StringId, StringTable, Writer,
1010
};
1111

1212
/// The number assigned to the first special opcode.
@@ -29,7 +29,7 @@ pub struct LineProgram {
2929
/// directory of the compilation unit.
3030
///
3131
/// The first entry is for the working directory of the compilation unit.
32-
directories: IndexSet<LineString>,
32+
directories: FnvIndexSet<LineString>,
3333

3434
/// A list of source file entries.
3535
///
@@ -39,7 +39,7 @@ pub struct LineProgram {
3939
/// directory. Otherwise the directory is meaningless.
4040
///
4141
/// Does not include comp_file, even for version >= 5.
42-
files: IndexMap<(LineString, DirectoryId), FileInfo>,
42+
files: FnvIndexMap<(LineString, DirectoryId), FileInfo>,
4343

4444
/// True if the file entries may have valid timestamps.
4545
///
@@ -114,8 +114,8 @@ impl LineProgram {
114114
none: false,
115115
encoding,
116116
line_encoding,
117-
directories: IndexSet::new(),
118-
files: IndexMap::new(),
117+
directories: FnvIndexSet::default(),
118+
files: FnvIndexMap::default(),
119119
prev_row: LineRow::initial_state(encoding, line_encoding),
120120
row: LineRow::initial_state(encoding, line_encoding),
121121
instructions: Vec::new(),
@@ -157,8 +157,8 @@ impl LineProgram {
157157
none: true,
158158
encoding,
159159
line_encoding,
160-
directories: IndexSet::new(),
161-
files: IndexMap::new(),
160+
directories: FnvIndexSet::default(),
161+
files: FnvIndexMap::default(),
162162
prev_row: LineRow::initial_state(encoding, line_encoding),
163163
row: LineRow::initial_state(encoding, line_encoding),
164164
instructions: Vec::new(),

src/write/loc.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
use alloc::vec::Vec;
2-
use indexmap::IndexSet;
32
use std::ops::{Deref, DerefMut};
43

54
use crate::common::{Encoding, LocationListsOffset, SectionId};
65
use crate::write::{
7-
Address, BaseId, DebugInfoFixup, Error, Expression, Result, Section, Sections, UnitOffsets,
8-
Writer,
6+
Address, BaseId, DebugInfoFixup, Error, Expression, FnvIndexSet, Result, Section, Sections,
7+
UnitOffsets, Writer,
98
};
109

1110
define_section!(
@@ -33,7 +32,7 @@ define_id!(
3332
#[derive(Debug, Default)]
3433
pub struct LocationListTable {
3534
base_id: BaseId,
36-
locations: IndexSet<LocationList>,
35+
locations: FnvIndexSet<LocationList>,
3736
}
3837

3938
impl LocationListTable {

src/write/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ use std::result;
6565

6666
use crate::constants;
6767

68+
type FnvIndexMap<T, V> = indexmap::IndexMap<T, V, fnv::FnvBuildHasher>;
69+
type FnvIndexSet<T> = indexmap::IndexSet<T, fnv::FnvBuildHasher>;
70+
6871
mod endian_vec;
6972
pub use self::endian_vec::*;
7073

src/write/range.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use alloc::vec::Vec;
2-
use indexmap::IndexSet;
32
use std::ops::{Deref, DerefMut};
43

54
use crate::common::{Encoding, RangeListsOffset, SectionId};
6-
use crate::write::{Address, BaseId, Error, Result, Section, Sections, Writer};
5+
use crate::write::{Address, BaseId, Error, FnvIndexSet, Result, Section, Sections, Writer};
76

87
define_section!(
98
DebugRanges,
@@ -30,7 +29,7 @@ define_id!(
3029
#[derive(Debug, Default)]
3130
pub struct RangeListTable {
3231
base_id: BaseId,
33-
ranges: IndexSet<RangeList>,
32+
ranges: FnvIndexSet<RangeList>,
3433
}
3534

3635
impl RangeListTable {

src/write/str.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use alloc::vec::Vec;
2-
use indexmap::IndexSet;
32
use std::ops::{Deref, DerefMut};
43

54
use crate::common::{DebugLineStrOffset, DebugStrOffset, SectionId};
6-
use crate::write::{BaseId, Result, Section, Writer};
5+
use crate::write::{BaseId, FnvIndexSet, Result, Section, Writer};
76

87
// Requirements:
98
// - values are `[u8]`, null bytes are not allowed
@@ -23,7 +22,7 @@ macro_rules! define_string_table {
2322
#[derive(Debug, Default)]
2423
pub struct $name {
2524
base_id: BaseId,
26-
strings: IndexSet<Vec<u8>>,
25+
strings: FnvIndexSet<Vec<u8>>,
2726
offsets: Vec<$offset>,
2827
len: usize,
2928
}

src/write/unit.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,11 +1530,11 @@ pub(crate) mod convert {
15301530
use crate::write::{
15311531
self, ConvertError, ConvertLineProgram, ConvertResult, Dwarf, LocationList, RangeList,
15321532
};
1533-
use fnv::FnvHashMap as HashMap;
1533+
use fnv::FnvHashMap;
15341534

15351535
#[derive(Debug, Default)]
15361536
struct FilterDependencies {
1537-
edges: HashMap<UnitSectionOffset, Vec<UnitSectionOffset>>,
1537+
edges: FnvHashMap<UnitSectionOffset, Vec<UnitSectionOffset>>,
15381538
required: Vec<UnitSectionOffset>,
15391539
}
15401540

@@ -2050,7 +2050,7 @@ pub(crate) mod convert {
20502050
///
20512051
/// If this is set then `from_units` will contain exactly one unit.
20522052
from_skeleton_unit: Option<read::UnitRef<'a, R>>,
2053-
entry_ids: HashMap<UnitSectionOffset, (UnitId, UnitEntryId)>,
2053+
entry_ids: FnvHashMap<UnitSectionOffset, (UnitId, UnitEntryId)>,
20542054
dwarf: &'a mut Dwarf,
20552055
}
20562056

@@ -2065,7 +2065,7 @@ pub(crate) mod convert {
20652065
from_units: Vec::new(),
20662066
from_unit_index: 0,
20672067
from_skeleton_unit: None,
2068-
entry_ids: HashMap::default(),
2068+
entry_ids: FnvHashMap::default(),
20692069
dwarf,
20702070
};
20712071

@@ -2096,7 +2096,7 @@ pub(crate) mod convert {
20962096
from_units: Vec::new(),
20972097
from_unit_index: 0,
20982098
from_skeleton_unit: filter.skeleton_unit,
2099-
entry_ids: HashMap::default(),
2099+
entry_ids: FnvHashMap::default(),
21002100
dwarf,
21012101
};
21022102

@@ -2184,7 +2184,7 @@ pub(crate) mod convert {
21842184
from_dwarf: &'a read::Dwarf<R>,
21852185
from_unit: read::Unit<R>,
21862186
from_skeleton_unit: read::UnitRef<'a, R>,
2187-
entry_ids: HashMap<UnitSectionOffset, (UnitId, UnitEntryId)>,
2187+
entry_ids: FnvHashMap<UnitSectionOffset, (UnitId, UnitEntryId)>,
21882188
unit_id: UnitId,
21892189
unit: &'a mut write::Unit,
21902190
line_strings: &'a mut write::LineStringTable,
@@ -2243,7 +2243,7 @@ pub(crate) mod convert {
22432243
let unit_id = skeleton.unit_id;
22442244
let unit = &mut *skeleton.unit;
22452245

2246-
let mut entry_ids = HashMap::default();
2246+
let mut entry_ids = FnvHashMap::default();
22472247
entry_ids.insert(root_offset, (unit_id, unit.root()));
22482248
for offset in offsets {
22492249
entry_ids.insert(offset, (unit_id, unit.reserve()));
@@ -2387,7 +2387,7 @@ pub(crate) mod convert {
23872387
/// The table containing converted strings.
23882388
pub strings: &'a mut write::StringTable,
23892389
line_program_files: Vec<FileId>,
2390-
entry_ids: &'a HashMap<UnitSectionOffset, (UnitId, UnitEntryId)>,
2390+
entry_ids: &'a FnvHashMap<UnitSectionOffset, (UnitId, UnitEntryId)>,
23912391
from_entries: read::EntriesRaw<'a, 'a, R>,
23922392
parents: Vec<(isize, UnitEntryId)>,
23932393
}

0 commit comments

Comments
 (0)