kreeti / kt-paperclip

Easy file attachment management for ActiveRecord
Other
275 stars 95 forks source link

Use a thread local variable for recursion checking #106

Closed tenderlove closed 1 year ago

tenderlove commented 1 year ago

Checking the stack callstack is extremely expensive. Use a thread local variable for detecting recursion and raising an exception.

Using the stacktrace means that JITs must exit because the stack must be reconstructed. On top of that, the deeper the call stack, the more expensive constructing the call stack becomes. This commit should provide the same safety, but be much cheaper than building a call stack.

For context, I was looking at some profiles of Mastodon, and I guess url is a popular (and expensive) method. 😅

Thanks!

summera commented 1 year ago

@ssinghi any chance we can get a new release up on Rubygems with this change sometime soon? Thanks!