Speed up clip_osm. From 45s for washington-latest->ballard down to 25s, just by buffering IO. Derp. #523

This commit is contained in:
Dustin Carlino 2021-03-18 09:13:11 -07:00
parent 396051faf4
commit 565f362d73

View File

@ -1,5 +1,6 @@
use std::collections::{HashMap, HashSet};
use std::fs::File;
use std::io::{BufReader, BufWriter};
use anyhow::Result;
use geo::prelude::Contains;
@ -35,8 +36,7 @@ fn clip(pbf_path: &str, boundary: &Polygon<f64>, out_path: &str) -> Result<()> {
let mut ways: HashMap<i64, RcWay> = HashMap::new();
let mut relations: HashMap<i64, RcRelation> = HashMap::new();
// TODO Buffer?
let mut reader = osmio::pbf::PBFReader::new(File::open(pbf_path)?);
let mut reader = osmio::pbf::PBFReader::new(BufReader::new(File::open(pbf_path)?));
for obj in reader.objects() {
match obj.object_type() {
OSMObjectType::Node => {
@ -76,8 +76,7 @@ fn clip(pbf_path: &str, boundary: &Polygon<f64>, out_path: &str) -> Result<()> {
used_nodes.extend(way.nodes().into_iter().cloned());
}
// TODO Buffer?
let mut writer = osmio::xml::XMLWriter::new(File::create(out_path)?);
let mut writer = osmio::xml::XMLWriter::new(BufWriter::new(File::create(out_path)?));
// TODO Nondetermistic output because of HashMap!
for id in used_nodes {
if let Some(node) = nodes.remove(&id) {