Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Permit building coder maps ahead-of-time of TypeMap init
Building coder maps can be quite expensive, building them ahead-of-time allows them to be reused for multiple type map creations, e.g. if creating both BasicTypeMapForQueries and BasicTypeMapForResults the cost need only be paid once. Example usage: conn = PG.connect(…) coder_maps = BasicTypeRegistry.build_coder_maps(conn) tmq = BasicTypeMapForQueries.new(conn, coder_maps: coder_maps) tmr = BasicTypeMapForResults.new(conn, coder_maps: coder_maps) Testing methodology: - 189k rows returned from pg_type query in `build_coder_maps`. - Cached and injected results from query to remove query cost and jitter from baseline. - Timing calling `PG::BasicTypeMapForQueries.new` only, figures are average of 32 iterations. - “Cached” calls `build_coder_maps` ahead-of-time, outside the timing loop, and passes-in. runtime Baseline: 374±16 ms Cached : <1± 0 ms (-99%) This confirms that the majority of the cost in creating a new type map is, when ignoring SQL query and results materialization, enclosed within `build_coder_maps`. As such, for *n* type maps, this reduces the (sometimes non-small) time complexity effectively from O(n) → O(1).
- Loading branch information