<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to 128: DateTime conversion to java.sql types is slow</title><link>https://sourceforge.net/p/jtds/patches/128/</link><description>Recent changes to 128: DateTime conversion to java.sql types is slow</description><atom:link href="https://sourceforge.net/p/jtds/patches/128/feed.rss" rel="self"/><language>en</language><lastBuildDate>Thu, 02 Oct 2014 08:54:08 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/jtds/patches/128/feed.rss" rel="self" type="application/rss+xml"/><item><title>#128 DateTime conversion to java.sql types is slow</title><link>https://sourceforge.net/p/jtds/patches/128/?limit=25#7022</link><description>&lt;div class="markdown_content"&gt;&lt;p&gt;Attached &lt;strong&gt;GregorianCalendar.patch&lt;/strong&gt; that replaces all occurrences of the &lt;code&gt;new GregorianCalendar&lt;/code&gt; calls inside jTDS 1.3.1 code, which is only &lt;code&gt;DateTime&lt;/code&gt; and &lt;code&gt;Support&lt;/code&gt; classes.&lt;/p&gt;&lt;/div&gt;</description><pubDate>Thu, 02 Oct 2014 08:54:08 -0000</pubDate><guid>https://sourceforge.netca45c0f36f0778eb979f5a2e822630464ea853e6</guid></item><item><title>#128 DateTime conversion to java.sql types is slow</title><link>https://sourceforge.net/p/jtds/patches/128/?limit=25#1847</link><description>&lt;div class="markdown_content"&gt;&lt;p&gt;The patch was created against &lt;code&gt;DateTime&lt;/code&gt; class from version &lt;strong&gt;1.3.1&lt;/strong&gt;.&lt;/p&gt;&lt;/div&gt;</description><pubDate>Wed, 01 Oct 2014 09:25:26 -0000</pubDate><guid>https://sourceforge.net35177a5640c1c7b8ce6bffa5d7d6a18b9cb9dad6</guid></item><item><title>#128 DateTime conversion to java.sql types is slow</title><link>https://sourceforge.net/p/jtds/patches/128/?limit=25#1463</link><description>&lt;div class="markdown_content"&gt;&lt;p&gt;&lt;strong&gt;Benchmark results&lt;/strong&gt;:&lt;br /&gt;
&lt;img src="https://sourceforge.net/p/jtds/patches/_discuss/thread/fdb18a35/4eaf/attachment/DateTime_benchmark_results.png" /&gt;&lt;/p&gt;&lt;/div&gt;</description><pubDate>Wed, 01 Oct 2014 09:24:11 -0000</pubDate><guid>https://sourceforge.neteaec5d3e9d8ec2fc121a2894d5938c67b6850d41</guid></item><item><title>#128 DateTime conversion to java.sql types is slow</title><link>https://sourceforge.net/p/jtds/patches/128/?limit=25#4eaf</link><description>&lt;div class="markdown_content"&gt;&lt;p&gt;Patch and benchmark results attached&lt;/p&gt;&lt;/div&gt;</description><pubDate>Wed, 01 Oct 2014 09:21:35 -0000</pubDate><guid>https://sourceforge.net527c46ba97ef367382820440d6f6b19f9a15d1ac</guid></item><item><title>DateTime conversion to java.sql types is slow</title><link>https://sourceforge.net/p/jtds/patches/128/</link><description>&lt;div class="markdown_content"&gt;&lt;p&gt;Methods on &lt;code&gt;net.sourceforge.jtds.jdbc.DateTime&lt;/code&gt; class such as &lt;code&gt;toDate()&lt;/code&gt;, &lt;code&gt;toTime()&lt;/code&gt; and &lt;code&gt;toTimestamp()&lt;/code&gt; create new instance of the &lt;code&gt;java.util.GregorianCalendar&lt;/code&gt;. But creating &lt;code&gt;java.util.GregorianCalendar&lt;/code&gt; is very costly operation that translates into poor performance when unpacking dates from &lt;code&gt;ResultSet&lt;/code&gt;.&lt;br /&gt;
Moreover the &lt;code&gt;DateTime&lt;/code&gt; class creates &lt;code&gt;GregorianCalendar&lt;/code&gt; in other places such as constructors and &lt;code&gt;packTime()&lt;/code&gt; method.&lt;/p&gt;
&lt;p&gt;To solve the problem I suggest to re-use &lt;code&gt;Calendar&lt;/code&gt; instance. The easiest is to use &lt;code&gt;ThreadLocal&lt;/code&gt; to store &lt;code&gt;GregorianCalendar&lt;/code&gt;. And that's exactly what is done in the attached patch. Another option would be to pass &lt;code&gt;GregorianCalendar&lt;/code&gt; to &lt;code&gt;DateTime&lt;/code&gt; when it is created but that would require to update all places where &lt;code&gt;DateTime&lt;/code&gt; is used.&lt;br /&gt;
&lt;strong&gt;NOTE:&lt;/strong&gt; the patch does not cleanup &lt;code&gt;ThreadLocal&lt;/code&gt; but one can easily add a &lt;code&gt;removeCalendar&lt;/code&gt; static method which can be called for example when underlying &lt;code&gt;ResultSet&lt;/code&gt; is closed and will remove calendar instance from &lt;code&gt;ThreadLocal&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;I'm also attaching the &lt;code&gt;DateTimeBenchmark&lt;/code&gt; class which is a micro-benchmark written using &lt;a class="" href="http://openjdk.java.net/projects/code-tools/jmh" rel="nofollow"&gt;JMH&lt;/a&gt; framework. The results of running benchmark on original code and code with the patch included are shown below (&lt;em&gt;time is nanoseconds per operation&lt;/em&gt;):&lt;br /&gt;
[-img src=DateTime_benchmark_results.png alt=Benchmark results: missing =-]&lt;/p&gt;&lt;/div&gt;</description><pubDate>Wed, 01 Oct 2014 09:20:46 -0000</pubDate><guid>https://sourceforge.net8c44d12a1cf209c12a28f7670655faa0bb8ee706</guid></item></channel></rss>