I’m writing a Rails application, using the ‘json’ gem, and its behavior where it can switch between the ‘json/pure’ and ‘json/ext’ implementations is causing problems. Specifically, sometimes a gem introduces a line like
require 'json/pure'
When that happens, JSON.parser and JSON.generator switch to the slow, ruby-based version globally. Then every call to JSON.parse and JSON.generate are slow.
I want to avoid the situation where a changing gem dependency, unbeknownst to me, suddenly makes my site much slower. How can I prevent ‘json/pure’ from ever being loaded, enforce ‘json/ext’ usage, or otherwise prevent this problem in the future?
To prevent json/pure from being loaded, this works:
You have to run this before json/pure is required.