Omniauth impact on non omniauth routes
Author: SamSaffronCreated Jan 15, 2018Updated Nov 11, 2023
Omniauth seems to spend time (and allocate lots of objects) in its internal middleware stack on every request.
https://gist.github.com/SamSaffron/2c7f2ce4089abf0375c5be9cfbbfefb1
This is clearly totally unneeded in non omniauth routes. I created a simple middleware in Discourse to bypass per:
https://github.com/discourse/discourse/commit/442a17bfb2b543cdae33b825e249b5e61ec0b45a
I wonder
- How safe is this, does omniauth need access to non
/authroutes? - Is a similar pattern doable out-of-the-box?
Also: memory profiler report:
allocated objects by location
-----------------------------------
522 /home/sam/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/hashie-3.5.5/lib/hashie/mash.rb:353
382 /home/sam/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/hashie-3.5.5/lib/hashie/mash.rb:316
252 /home/sam/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/hashie-3.5.5/lib/hashie/mash.rb:311
67 /home/sam/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/hashie-3.5.5/lib/hashie/mash.rb:189
32 /home/sam/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/hashie-3.5.5/lib/hashie/mash.rb:331
24 /home/sam/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/omniauth-1.6.1/lib/omniauth/strategy.rb:138
21 /home/sam/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/rack-2.0.3/lib/rack/builder.rb:86
16 /home/sam/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/hashie-3.5.5/lib/hashie/mash.rb:329^^^ All allocated by omniauth on a non omniauth related route
allocated memory by class
-----------------------------------
45006 String
38320 Array
18176 OmniAuth::Strategy::Options
13128 Hash^^^ mostly omniauth
Source: omniauth/omniauth