<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: TValue is very slow!</title>
	<atom:link href="http://tech.turbu-rpg.com/100/tvalue-is-very-slow/feed" rel="self" type="application/rss+xml" />
	<link>http://tech.turbu-rpg.com/100/tvalue-is-very-slow</link>
	<description>My thoughts on Delphi programming in general, and particularly on the technical aspects of developing the TURBU engine and editor.</description>
	<lastBuildDate>Sun, 29 Jan 2012 00:52:04 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Chris</title>
		<link>http://tech.turbu-rpg.com/100/tvalue-is-very-slow/comment-page-1#comment-202</link>
		<dc:creator>Chris</dc:creator>
		<pubDate>Thu, 18 Mar 2010 20:26:33 +0000</pubDate>
		<guid isPermaLink="false">http://tech.turbu-rpg.com/?p=100#comment-202</guid>
		<description>Joylon - &#039;rather than creating something entirely new from scratch&#039;

That&#039;s a rather ironic thing to say given the performance issue in question arises from TValue ultimately piggy-backing on something old, namely the long-standing internal routine that gets invoked whenever one record with managed fields is assigned to another. Moreover, there remains the basic point that, contra what the help says, TValue *isn&#039;t* a &#039;lightweight version of Variant&#039; at all, but something different with a different purpose.

Now of course, maybe the Variant type *should* be extended to better reflect its name rather than its OLE Automation-supporting origins - for myself, I&#039;ve always found it odd that it supports native Delphi strings yet not native Delphi objects, and as a result, barely gives you much more than the strict OLE Automation subset that is OleVariant, D6+&#039;s custom variant support notwithstanding. Nonetheless, that&#039;s a distinct issue to the one at hand.</description>
		<content:encoded><![CDATA[<p>Joylon &#8211; &#8216;rather than creating something entirely new from scratch&#8217;</p>
<p>That&#8217;s a rather ironic thing to say given the performance issue in question arises from TValue ultimately piggy-backing on something old, namely the long-standing internal routine that gets invoked whenever one record with managed fields is assigned to another. Moreover, there remains the basic point that, contra what the help says, TValue *isn&#8217;t* a &#8216;lightweight version of Variant&#8217; at all, but something different with a different purpose.</p>
<p>Now of course, maybe the Variant type *should* be extended to better reflect its name rather than its OLE Automation-supporting origins &#8211; for myself, I&#8217;ve always found it odd that it supports native Delphi strings yet not native Delphi objects, and as a result, barely gives you much more than the strict OLE Automation subset that is OleVariant, D6+&#8217;s custom variant support notwithstanding. Nonetheless, that&#8217;s a distinct issue to the one at hand.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jolyon Smith</title>
		<link>http://tech.turbu-rpg.com/100/tvalue-is-very-slow/comment-page-1#comment-200</link>
		<dc:creator>Jolyon Smith</dc:creator>
		<pubDate>Wed, 17 Mar 2010 20:42:55 +0000</pubDate>
		<guid isPermaLink="false">http://tech.turbu-rpg.com/?p=100#comment-200</guid>
		<description>Then extend Variant or use Variant internally, rather than come up with a.n.other entirely new &quot;like a variant but not Variant&quot; implementation.  At the very least take the bit&#039;s of Variant that are performant (yuck word) and add the twiddly bits that are needed, rather than creating something entirely new from scratch.  But as I say, I suspect that this approach wasn&#039;t &quot;sexy&quot; enough.</description>
		<content:encoded><![CDATA[<p>Then extend Variant or use Variant internally, rather than come up with a.n.other entirely new &#8220;like a variant but not Variant&#8221; implementation.  At the very least take the bit&#8217;s of Variant that are performant (yuck word) and add the twiddly bits that are needed, rather than creating something entirely new from scratch.  But as I say, I suspect that this approach wasn&#8217;t &#8220;sexy&#8221; enough.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris</title>
		<link>http://tech.turbu-rpg.com/100/tvalue-is-very-slow/comment-page-1#comment-199</link>
		<dc:creator>Chris</dc:creator>
		<pubDate>Wed, 17 Mar 2010 13:30:41 +0000</pubDate>
		<guid isPermaLink="false">http://tech.turbu-rpg.com/?p=100#comment-199</guid>
		<description>Joylon - what&#039;s with the snark? I take it you haven&#039;t actually tried to put something as basic as (say) an enum value or an object reference into a variant? Obviously, you could hack this, but the code required would presumably mean replicating a lot of TValue if the actual type (and not just the ordinal value) is to be roundtrippable.</description>
		<content:encoded><![CDATA[<p>Joylon &#8211; what&#8217;s with the snark? I take it you haven&#8217;t actually tried to put something as basic as (say) an enum value or an object reference into a variant? Obviously, you could hack this, but the code required would presumably mean replicating a lot of TValue if the actual type (and not just the ordinal value) is to be roundtrippable.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jolyon Smith</title>
		<link>http://tech.turbu-rpg.com/100/tvalue-is-very-slow/comment-page-1#comment-196</link>
		<dc:creator>Jolyon Smith</dc:creator>
		<pubDate>Tue, 16 Mar 2010 21:13:00 +0000</pubDate>
		<guid isPermaLink="false">http://tech.turbu-rpg.com/?p=100#comment-196</guid>
		<description>I&#039;m curious ... if TValue is more specialised and Variant is more generalised, then it seems to me that Variant&#039;s could have been used everywhere that a TValue is used, so why re-invent an inferior wheel ?

As a type intended for the basis of a scripting engine, it seems to me that Variant would also be a natural choice for any other form of dynamic invocation, reflection based or not (most, if not all, &quot;scripting engine&#039;s&quot; involve some form of dynamic invocation, no?).

I suspect collective noses were turned up at Variants because they weren&#039;t &quot;Generic&quot; enough (note deliberate capitalisation and air-quotes).</description>
		<content:encoded><![CDATA[<p>I&#8217;m curious &#8230; if TValue is more specialised and Variant is more generalised, then it seems to me that Variant&#8217;s could have been used everywhere that a TValue is used, so why re-invent an inferior wheel ?</p>
<p>As a type intended for the basis of a scripting engine, it seems to me that Variant would also be a natural choice for any other form of dynamic invocation, reflection based or not (most, if not all, &#8220;scripting engine&#8217;s&#8221; involve some form of dynamic invocation, no?).</p>
<p>I suspect collective noses were turned up at Variants because they weren&#8217;t &#8220;Generic&#8221; enough (note deliberate capitalisation and air-quotes).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: François</title>
		<link>http://tech.turbu-rpg.com/100/tvalue-is-very-slow/comment-page-1#comment-195</link>
		<dc:creator>François</dc:creator>
		<pubDate>Tue, 16 Mar 2010 18:54:04 +0000</pubDate>
		<guid isPermaLink="false">http://tech.turbu-rpg.com/?p=100#comment-195</guid>
		<description>@Mason and commentators, 
Very interesting reading. Thanks!</description>
		<content:encoded><![CDATA[<p>@Mason and commentators,<br />
Very interesting reading. Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Barry Kelly</title>
		<link>http://tech.turbu-rpg.com/100/tvalue-is-very-slow/comment-page-1#comment-194</link>
		<dc:creator>Barry Kelly</dc:creator>
		<pubDate>Tue, 16 Mar 2010 13:06:50 +0000</pubDate>
		<guid isPermaLink="false">http://tech.turbu-rpg.com/?p=100#comment-194</guid>
		<description>And FWIW, your timings are likely to be processor sensitive. I ran it on my high-end desktop:

Variants: 473
TValues: 21853

By this test, over 40x slower :)</description>
		<content:encoded><![CDATA[<p>And FWIW, your timings are likely to be processor sensitive. I ran it on my high-end desktop:</p>
<p>Variants: 473<br />
TValues: 21853</p>
<p>By this test, over 40x slower <img src='http://tech.turbu-rpg.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Barry Kelly</title>
		<link>http://tech.turbu-rpg.com/100/tvalue-is-very-slow/comment-page-1#comment-193</link>
		<dc:creator>Barry Kelly</dc:creator>
		<pubDate>Tue, 16 Mar 2010 13:01:44 +0000</pubDate>
		<guid isPermaLink="false">http://tech.turbu-rpg.com/?p=100#comment-193</guid>
		<description>TValue isn&#039;t optimized for speed, and I wouldn&#039;t describe it as &quot;a lightweight Variant&quot;. It&#039;s explicitly designed to not be like Variant - Variants can change type depending on context, while TValue doesn&#039;t. TValue is designed to model the Delphi type system dynamically so that values can be transported with high fidelity to and from dynamic invocation. Variant was designed to model Excel spreadsheet cells, and extended to be the basic type of a scripting engine - naturally it has had far more focus on performance.

But yes, things can be improved with TValue performance wise, but be aware that any gains in practice will be limited owing to the fact that the overhead of reflection-based invocation will still add up. The dynamic invocation logic can itself be optimized by precomputing more things and reducing the number of copies, but again it&#039;s still not going to be competitive with native invocations.</description>
		<content:encoded><![CDATA[<p>TValue isn&#8217;t optimized for speed, and I wouldn&#8217;t describe it as &#8220;a lightweight Variant&#8221;. It&#8217;s explicitly designed to not be like Variant &#8211; Variants can change type depending on context, while TValue doesn&#8217;t. TValue is designed to model the Delphi type system dynamically so that values can be transported with high fidelity to and from dynamic invocation. Variant was designed to model Excel spreadsheet cells, and extended to be the basic type of a scripting engine &#8211; naturally it has had far more focus on performance.</p>
<p>But yes, things can be improved with TValue performance wise, but be aware that any gains in practice will be limited owing to the fact that the overhead of reflection-based invocation will still add up. The dynamic invocation logic can itself be optimized by precomputing more things and reducing the number of copies, but again it&#8217;s still not going to be competitive with native invocations.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mason Wheeler</title>
		<link>http://tech.turbu-rpg.com/100/tvalue-is-very-slow/comment-page-1#comment-191</link>
		<dc:creator>Mason Wheeler</dc:creator>
		<pubDate>Tue, 16 Mar 2010 10:28:27 +0000</pubDate>
		<guid isPermaLink="false">http://tech.turbu-rpg.com/?p=100#comment-191</guid>
		<description>Robert:  I tried those and got:

Variants: 1551
TValues: 1977

Much better!

Ken: *grin* I guess I&#039;m still learning.</description>
		<content:encoded><![CDATA[<p>Robert:  I tried those and got:</p>
<p>Variants: 1551<br />
TValues: 1977</p>
<p>Much better!</p>
<p>Ken: *grin* I guess I&#8217;m still learning.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ken Knopfli</title>
		<link>http://tech.turbu-rpg.com/100/tvalue-is-very-slow/comment-page-1#comment-190</link>
		<dc:creator>Ken Knopfli</dc:creator>
		<pubDate>Tue, 16 Mar 2010 06:36:36 +0000</pubDate>
		<guid isPermaLink="false">http://tech.turbu-rpg.com/?p=100#comment-190</guid>
		<description>I learn a lot from your blog.

You post your posit, then dozens of pundits chime in to show where you are going wrong.</description>
		<content:encoded><![CDATA[<p>I learn a lot from your blog.</p>
<p>You post your posit, then dozens of pundits chime in to show where you are going wrong.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Robert Love</title>
		<link>http://tech.turbu-rpg.com/100/tvalue-is-very-slow/comment-page-1#comment-189</link>
		<dc:creator>Robert Love</dc:creator>
		<pubDate>Tue, 16 Mar 2010 05:17:07 +0000</pubDate>
		<guid isPermaLink="false">http://tech.turbu-rpg.com/?p=100#comment-189</guid>
		<description>Here is a type safe version of the two methods that results in similar performance, with TValue being slightly faster.   I am sure it could be optimized more if conversions need to occur.

class operator TValue.Implicit(Value: Integer): TValue;
begin
  result.FData.FTypeInfo := System.TypeInfo(Integer);
  result.FData.FAsSLong := Value;
  result.FData.FHeapData := IInterface(Nop_Instance);
end;

function TValue.AsInteger: Integer;
begin
  if (FData.FTypeInfo = System.TypeInfo(Integer)) and Assigned(FData.FHeapData) then
  begin
   result := FData.FAsSLong;
  end
  else
    Result := AsType;
end;</description>
		<content:encoded><![CDATA[<p>Here is a type safe version of the two methods that results in similar performance, with TValue being slightly faster.   I am sure it could be optimized more if conversions need to occur.</p>
<p>class operator TValue.Implicit(Value: Integer): TValue;<br />
begin<br />
  result.FData.FTypeInfo := System.TypeInfo(Integer);<br />
  result.FData.FAsSLong := Value;<br />
  result.FData.FHeapData := IInterface(Nop_Instance);<br />
end;</p>
<p>function TValue.AsInteger: Integer;<br />
begin<br />
  if (FData.FTypeInfo = System.TypeInfo(Integer)) and Assigned(FData.FHeapData) then<br />
  begin<br />
   result := FData.FAsSLong;<br />
  end<br />
  else<br />
    Result := AsType;<br />
end;</p>
]]></content:encoded>
	</item>
</channel>
</rss>

