Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find query_source_location using lazy Enumerator #35985

Merged
merged 1 commit into from
Apr 16, 2019

Conversation

jhawthorn
Copy link
Member

@jhawthorn jhawthorn commented Apr 15, 2019

In development, extract_query_source_location is called on every SQL query. In my test app, a SQL query from the controller results in a stack trace 200 deep, with the first "clean" frame 60 in.

By filtering on caller.lazy, a lazy enumerator, instead of the full array, we only need to filter the backtrace up to the first non-noise stack frame.

This also updates noise to be able to deal with being passed a lazy enum. We don't need this anywhere, but it seemed better for this to be consistent.

Benchmark:

       clean(caller)      1.505k (± 3.7%) i/s -      7.550k in   5.022886s
clean(caller.lazy).to_a
                          1.258k (± 3.7%) i/s -      6.375k in   5.074642s
clean(caller, :noise)
                          1.474k (± 3.6%) i/s -      7.497k in   5.091694s
clean(caller.lazy).first
                          3.841k (± 3.7%) i/s -     19.482k in   5.079535s

There are a few more improvements I'd like to make to this later, running X regex against Y strings for Z queries ends up pretty expensive even for development. It would be really great if we had an interface to filter on caller_locations (Thread::Backtrace::Location) instead of caller.

This way, we only need to filter the backtrace up to the first non-noise
stack frame.

This also updates noise to be able to deal with being passed a lazy
enum. We don't need this anywhere, but it seemed better for this to be
consistent.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants