Skip to content

fix(sql): Optimize GetLatestObservations#140

Merged
devsjc merged 1 commit intomainfrom
devsjc/latest-obs-speedup
Mar 24, 2026
Merged

fix(sql): Optimize GetLatestObservations#140
devsjc merged 1 commit intomainfrom
devsjc/latest-obs-speedup

Conversation

@devsjc
Copy link
Contributor

@devsjc devsjc commented Mar 24, 2026

Contribution Checklist

  • Have you followed the Open Climate Fix Contribution Guidelines?
  • Have you referenced the Issue this PR addresses, where applicable?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added a summary of the changes?
  • Have you written new tests for your changes, where applicable?
  • Have you successfully run make lint with your changes locally?
  • Have you successfully run make test with your changes locally?

Warning

PRs may be closed if all the above boxes are not checked.

Changes in this Pull Request

Optimizes GetLatestObservations by using a reverse index scan.

@github-actions
Copy link

Benchmark Results

Benchmark results
?   	github.com/openclimatefix/data-platform/cmd	[no test files]
?   	github.com/openclimatefix/data-platform/internal/gen/ocf/dp	[no test files]
?   	github.com/openclimatefix/data-platform/internal/interceptors	[no test files]
PASS
ok  	github.com/openclimatefix/data-platform/internal/server/dummy	0.005s
{"level":"debug","time":"2026-03-24T21:55:22Z","message":"Completed migrations"}
goos: linux
goarch: amd64
pkg: github.com/openclimatefix/data-platform/internal/server/postgres
cpu: AMD EPYC 7763 64-Core Processor                
BenchmarkPostgresClient/small/GetForecastAsTimeseries-4         	      72	  15507660 ns/op
BenchmarkPostgresClient/small/GetForecastAtTimestamp-4          	      86	  13770058 ns/op
BenchmarkPostgresClient/small/GetObservationsAsTimeseries-4     	     925	   1253603 ns/op
BenchmarkPostgresClient/small/CreateForecast-4                  	      91	  12800730 ns/op
PASS
ok  	github.com/openclimatefix/data-platform/internal/server/postgres	72.280s
?   	github.com/openclimatefix/data-platform/internal/server/postgres/gen	[no test files]
Benchmark vs base branch
goos: linux
goarch: amd64
pkg: github.com/openclimatefix/data-platform/internal/server/postgres
cpu: AMD EPYC 7763 64-Core Processor                
                                                   │ bench-main.txt │ bench-devsjc-latest-obs-speedup.txt  │
                                                   │     sec/op     │    sec/op     vs base                │
PostgresClient/small/GetForecastAsTimeseries-4         17.55m ± ∞ ¹   15.51m ± ∞ ¹       ~ (p=1.000 n=1) ²
PostgresClient/small/GetForecastAtTimestamp-4          14.24m ± ∞ ¹   13.77m ± ∞ ¹       ~ (p=1.000 n=1) ²
PostgresClient/small/GetObservationsAsTimeseries-4     1.285m ± ∞ ¹   1.254m ± ∞ ¹       ~ (p=1.000 n=1) ²
PostgresClient/small/CreateForecast-4                  13.50m ± ∞ ¹   12.80m ± ∞ ¹       ~ (p=1.000 n=1) ²
geomean                                                8.114m         7.651m        -5.70%
¹ need >= 6 samples for confidence interval at level 0.95
² need >= 4 samples to detect a difference at alpha level 0.05

@devsjc devsjc merged commit 615ce3e into main Mar 24, 2026
4 checks passed
@devsjc devsjc deleted the devsjc/latest-obs-speedup branch March 24, 2026 21:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant