String concatenation is generally expensive. Collecting all the tokens
in an array and .joining them if a common idiom you might consider
employing if you're beginning to think about performance issues.
Memoizing as much of the generated SQL as possible could be an
advantage for the kind of use cases I have. On the other hand: it's
Ruby. There's only so much you can do without going down to C...

-p

On Wed, Mar 14, 2012 at 1:13 PM, Jeremy Evans <[email protected]> wrote:
> Profiling Sequel's performance on simple queries has shown that Sequel can
> spend more time building the SQL than the database does on executing it.
> There are a couple of likely reasons for this:
>
> * Ruby is slow (relative to the database)
> * Sequel's SQL generation code is very modular (lots of method calls)
>
> I can't do anything about the former, but the latter can be dealt with a
> fairly simple optimization, just manually inlining the method calls.  I have
> a patch that does that for the PostgreSQL adapter: http://pastie.org/3595976
>
> I'm leaning toward not applying this patch.  I suspect it will increase
> maintenance burden in the future, and while the gains for pure SQL
> generation of simple queries are substantial (~40% increase in my testing of
> simple queries on 1.9.3), I'm only seeing single-digit increases (7-10%) in
> performance for common cases that access the database (#all/#first).  Also,
> these increases are best-case scenarios, using very simple queries with a
> very optimized adapter (pg with sequel_pg).  Anyone who wants faster SQL
> generation for simple queries would be better off using one of the
> following:
>
> * A placeholder string: DB["SELECT * FROM table WHERE column = ?", value]
> (150% faster SQL generation)
> * A placeholder array: DB.dataset.with_sql(['SELECT * FROM table WHERE
> column = '], value) (260% faster SQL generation)
> * A prepared statement: ps = DB[:table].where(:column=>:$c).prepare(:select,
> :some_name); ps.call(:c=>value) (skips SQL generation completely when
> called)
>
> That being said, I'm still open to applying this patch depending on the
> response from the community.  Any thoughts about whether this patch should
> be applied?
>
> Jeremy
>
> --
> You received this message because you are subscribed to the Google Groups
> "sequel-talk" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/sequel-talk/-/Prn7T3gPemEJ.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/sequel-talk?hl=en.



-- 
Peter van Hardenberg
San Francisco, California
"Everything was beautiful, and nothing hurt." -- Kurt Vonnegut

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en.

Reply via email to