[openstreetmap/openstreetmap-website] Avoid using partial rendering in /map.json (PR #4141)

Stillhart notifications at github.com
Mon Aug 7 13:58:59 UTC 2023


Using partial rendering too many times is slow in rails and a known issue. This is because the whole render context is given to the partial. This view is using this extensively and thousands of times. Just inlining the "osm object" should improve the performance. At the same time a lot of code can be de-duplicated. I kept a fallback in case of new objects. 

Related rails issue: https://github.com/rails/rails/issues/41452

That halfed rendering times in my case, and reduced allocations by 20%. 
```log
# With my patch:
web_1  | Completed 200 OK in 232ms (Views: 108.1ms | ActiveRecord: 31.3ms | Allocations: 221573)
web_1  | Completed 200 OK in 219ms (Views: 115.8ms | ActiveRecord: 21.0ms | Allocations: 218252)
web_1  | Completed 200 OK in 254ms (Views: 143.9ms | ActiveRecord: 22.9ms | Allocations: 218254)
web_1  | Completed 200 OK in 222ms (Views: 115.7ms | ActiveRecord: 21.9ms | Allocations: 218313)

# Without my patch:
web_1  | Completed 200 OK in 438ms (Views: 332.1ms | ActiveRecord: 22.8ms | Allocations: 253255)
web_1  | Completed 200 OK in 398ms (Views: 295.7ms | ActiveRecord: 21.8ms | Allocations: 250814)
web_1  | Completed 200 OK in 447ms (Views: 343.2ms | ActiveRecord: 22.5ms | Allocations: 250473)
web_1  | Completed 200 OK in 448ms (Views: 338.7ms | ActiveRecord: 25.2ms | Allocations: 250530)
```
You can view, comment on, or merge this pull request online at:

  https://github.com/openstreetmap/openstreetmap-website/pull/4141

-- Commit Summary --

  * using partial rendering too many times is slow in rails and a known issue. this is because the whole render context is given to the partial. this view is using this extensively and thousands of times. just inlining the object should improve the performance. At the same time a lot of code can be de-duplicated. I kept a fallback in case of new objects. https://github.com/rails/rails/issues/41452

-- File Changes --

    M app/views/api/map/index.json.jbuilder (40)

-- Patch Links --

https://github.com/openstreetmap/openstreetmap-website/pull/4141.patch
https://github.com/openstreetmap/openstreetmap-website/pull/4141.diff

-- 
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/4141
You are receiving this because you are subscribed to this thread.

Message ID: <openstreetmap/openstreetmap-website/pull/4141 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20230807/1025dfb5/attachment.htm>


More information about the rails-dev mailing list