diff --git a/Cargo.toml b/Cargo.toml index 54abb54..b94250e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] description = "Read GTFS (public transit timetables) files" name = "gtfs-structures" -version = "0.36.0" +version = "0.36.1" authors = ["Tristram Gräbener ", "Antoine Desbordes "] repository = "https://github.com/rust-transit/gtfs-structure" license = "MIT" diff --git a/src/gtfs.rs b/src/gtfs.rs index c3ac5d0..7a54177 100644 --- a/src/gtfs.rs +++ b/src/gtfs.rs @@ -290,6 +290,10 @@ fn to_calendar_dates(cd: Vec) -> HashMap res } +// Number of stoptimes to `pop` from the list before using shrink_to_fit to reduce the memory footprint +// Hardcoded to what seems a sensible value, but if needed we could make this a parameter, feel free to open an issue if this could help +const NB_STOP_TIMES_BEFORE_SHRINK: usize = 1_000_000; + fn create_trips( raw_trips: Vec, mut raw_stop_times: Vec, @@ -311,7 +315,9 @@ fn create_trips( frequencies: vec![], })); + let mut st_idx = 0; while let Some(s) = raw_stop_times.pop() { + st_idx += 1; let trip = &mut trips .get_mut(&s.trip_id) .ok_or_else(|| Error::ReferenceError(s.trip_id.to_string()))?; @@ -319,7 +325,10 @@ fn create_trips( .get(&s.stop_id) .ok_or_else(|| Error::ReferenceError(s.stop_id.to_string()))?; trip.stop_times.push(StopTime::from(s, Arc::clone(stop))); - raw_stop_times.shrink_to_fit(); + if st_idx % NB_STOP_TIMES_BEFORE_SHRINK == 0 { + println!("hop on shrink = {}", st_idx); + raw_stop_times.shrink_to_fit(); + } } for trip in &mut trips.values_mut() {