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

Cache visitor dispatch on a per-visitor basis #204

Merged
merged 1 commit into from
Sep 11, 2013

Conversation

trptcolin
Copy link

Currently, visitor dispatch (via the DISPATCH) constant is cached on a global basis. This means that, for instance, Arel::Nodes::Union will work fine when you use visitors implementing visit_Arel_Nodes_Union directly, like Visitors::ToSql.

But if a visitor needs to go up the class hierarchy looking for the method, the dispatch table gets mutated. This is fine as a cache for a specific visitor class, assuming methods don't get added dynamically to the visitor classes (anybody doing that should probably expect problems anyway). But for this mutation to ruin other visitors' dispatch cache seems bad.

So this patch turns DISPATCH into a 2-level hash, first for the visitor class, then for the node class.

The alternatives I see are:

  • depend on clients to avoid calling methods implemented in ancestor classes (not awesome; they'd have to depend on implementation details)
  • get rid of this cache entirely (bad; presumably the cache is there for perf reasons)
  • depend on clients to call Arel::Visitors::Visitor::DISPATCH.clear (bad; they'd lose the perf benefits and have ugly code)

Thoughts?

tenderlove added a commit that referenced this pull request Sep 11, 2013
Cache visitor dispatch on a per-visitor basis
@tenderlove tenderlove merged commit bd6adc8 into rails:master Sep 11, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants