Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Major speedup in dataset creation

This takes the setting of the @quote_identifiers,
@identifier_input_method, @identifier_output_method, and @row_proc
out of Dataset#initialize and delays their initialization until
they are needed.  This makes dataset creation about 2.5x faster on
1.8 and 4.4x faster on 1.9, and dataset cloning about 40% faster
on 1.8 and 20% faster on 1..

The tradeoff is about a 33% decrease in performance of
input_identifier and output_identifier, which are not usually
called directly.  Overall performance decrease during literalization
is very small.  This is likely to be an overall performance benefit
for almost all Sequel code.
  • Loading branch information...
commit 4c9fe0626f85c7dc60d86a95f64a178be9047c7d 1 parent 927a2cc
Jeremy Evans authored
2  CHANGELOG
View
@@ -1,5 +1,7 @@
=== HEAD
+* Major speedup in dataset creation (jeremyevans)
+
* Replace internal implementation of eager_graph with much faster version (jeremyevans)
* Don't treat strings with leading zeros as octal format in the default typecasting (jeremyevans)
8 lib/sequel/dataset/features.rb
View
@@ -11,7 +11,13 @@ class Dataset
# Whether this dataset quotes identifiers.
def quote_identifiers?
- @quote_identifiers
+ if defined?(@quote_identifiers)
+ @quote_identifiers
+ elsif db.respond_to?(:quote_identifiers?)
+ @quote_identifiers = db.quote_identifiers?
+ else
+ @quote_identifiers = false
+ end
end
# Whether this dataset will provide accurate number of rows matched for
30 lib/sequel/dataset/misc.rb
View
@@ -27,13 +27,9 @@ class Dataset
# the Database#dataset method return an instance of that subclass.
def initialize(db, opts = nil)
@db = db
- @quote_identifiers = db.quote_identifiers? if db.respond_to?(:quote_identifiers?)
- @identifier_input_method = db.identifier_input_method if db.respond_to?(:identifier_input_method)
- @identifier_output_method = db.identifier_output_method if db.respond_to?(:identifier_output_method)
@opts = opts || {}
- @row_proc = nil
end
-
+
# Define a hash value such that datasets with the same DB, opts, and SQL
# will be consider equal.
def ==(o)
@@ -114,6 +110,30 @@ def hash
[db, opts.sort_by{|k| k.to_s}, sql].hash
end
+ # The String instance method to call on identifiers before sending them to
+ # the database.
+ def identifier_input_method
+ if defined?(@identifier_input_method)
+ @identifier_input_method
+ elsif db.respond_to?(:identifier_input_method)
+ @identifier_input_method = db.identifier_input_method
+ else
+ @identifier_input_method = nil
+ end
+ end
+
+ # The String instance method to call on identifiers before sending them to
+ # the database.
+ def identifier_output_method
+ if defined?(@identifier_output_method)
+ @identifier_output_method
+ elsif db.respond_to?(:identifier_output_method)
+ @identifier_output_method = db.identifier_output_method
+ else
+ @identifier_output_method = nil
+ end
+ end
+
# Returns a string representation of the dataset including the class name
# and the corresponding SQL select statement.
def inspect
4 lib/sequel/dataset/mutation.rb
View
@@ -21,10 +21,10 @@ def self.def_mutation_method(*meths)
def_mutation_method(*MUTATION_METHODS)
# Set the method to call on identifiers going into the database for this dataset
- attr_accessor :identifier_input_method
+ attr_writer :identifier_input_method
# Set the method to call on identifiers coming the database for this dataset
- attr_accessor :identifier_output_method
+ attr_writer :identifier_output_method
# Whether to quote identifiers for this dataset
attr_writer :quote_identifiers
Please sign in to comment.
Something went wrong with that request. Please try again.