File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -64,6 +64,20 @@ impl LibPostal {
6464 . collect :: < Vec < _ > > ( ) ;
6565 LibPostal { column_names }
6666 }
67+
68+ pub async fn prime ( ) {
69+ // "Prime" libpostal by forcing it to load its language model and associated data
70+ // into memory with a dummy call.
71+ let libpostal = LibPostal :: new ( ) ;
72+ let _ = libpostal
73+ . geocode_addresses ( & [ Address {
74+ street : "1 Main St" . to_owned ( ) ,
75+ city : Some ( "Anytown" . to_owned ( ) ) ,
76+ state : Some ( "VT" . to_owned ( ) ) ,
77+ zipcode : None ,
78+ } ] )
79+ . await ;
80+ }
6781}
6882
6983#[ async_trait]
Original file line number Diff line number Diff line change @@ -279,6 +279,11 @@ async fn main() -> Result<()> {
279279 let result = match opt. cmd {
280280 // Run in server mode.
281281 Some ( Command :: Server { listen_address } ) => {
282+ // If we're running in server mode, then prime libpostal to load its
283+ // model and data into memory. This can take 5-10 seconds,
284+ // and we'd prefer that it happens as part of application startup,
285+ // rather than at the time of the first request.
286+ LibPostal :: prime ( ) . await ;
282287 run_server ( & listen_address, geocoder) . await
283288 }
284289 // Run in CLI pipeline mode.
You can’t perform that action at this time.
0 commit comments