FastCode: Difference between revisions

Content deleted Content added
Bender the Bot (talk | contribs)
 
(49 intermediate revisions by 36 users not shown)
Line 1:
{{Short description|Project to optimize code for Embarcadero compilers}}
'''FastCode''' is an [[open source]] [[Computer programming|programming]] project aimedthat ataims to providingprovide enhancedoptimized [[runtime library]] routines for [[Embarcadero Delphi]] and [[C++Builder|C++ Builder]]. This Sincecommunity-driven itproject was started in 2003 by [[Dennis Kjaer Christensen]], itand has contributedsince highlycontributed optimisedoptimized functionality to the 32-bit Delphi [[Runtimeruntime library| (RTL]]). FastCode is unique among contributions to commercial compiler runtime libraries for its community-driven and open source nature.
 
Organized as a competition divided into challenges, FastCode focuses on optimizing specific functions against multiple targets. The project offers benchmarking tools and validation processes for each function contribution. Contributions are scored, with points awarded based on performance against the targets. Embarcadero recognizes and incorporates the code created by the FastCode team into their Delphi codebase. Most participants in this project are assembler developers who utilize processor-specific code. The list of challenges tackled by the FastCode project is extensive; it covers diverse areas ranging from string manipulation functions like PosEx or CompareText to mathematical operations such as Power or Int64Mul.
 
==Structure==
The project is organized as a competition divided into challenges. Each challenge takes one function and optimizes it against a number of targets. The project provides tools for [[benchmarking]] and validating each function contribution. One point is given per contribution (maximally one function per target is given points) and ten points are awarded for a target winner. A list with all contributors and their scores is maintained, and at the end of each year, until 2008, a winner iswas celebrated. [[Borland]], [[Codegear]] and [[Embarcadero Technologies|Embarcadero]], the owners of [[Delphi (software)|Delphi]] and [[C++ Builder]], have historically sponsored prizes.
 
The majority of participants in the competition are assembler developers who often utilize processor-specific 32-bit code and extra instruction sets, such as [[MMX (instruction set)|MMX]], [[Streaming SIMD Extensions|SSE]], [[SSE2]], [[SSE3]], [[SSSE3]] and [[SSE4]].<ref>{{cite web|url=http://www.gerixsoft.com/blog/delphi/fastcode|title=How to Optimize Delphi Application Performance to the Max using FastCode Library|publisher=|accessdate=3 September 2015}}</ref>
The project is organized as a competition divided into challenges. Each challenge takes one function and optimizes it against a number of targets. The project provides tools for [[benchmarking]] and validating each function contribution. One point is given per contribution (maximally one function per target is given points) and ten points are awarded for a target winner. A list with all contributors and their scores is maintained, and at the end of each year a winner is celebrated. [[Borland]], [[Codegear]] and [[Embarcadero]], the owners of [[Delphi]] and [[C++ Builder]], have historically sponsored prizes.
 
The project enjoys the support of [[Embarcadero]] who recognizes the contributions of the FastCode team and incorporates their code into the codebase for Delphi.<ref>{{cite web|url=http://blogs.embarcadero.com/nickhodges/2006/11/27/29891|title=Nick Hodges|publisher=|accessdate=3 September 2015}}{{Dead link|date=July 2025 |bot=InternetArchiveBot |fix-attempted=yes }}</ref> The default [[memory management|memory manager]] for [[Embarcadero Delphi]], FastMM4, is the winner of the FastCode Memory Manager challenge.<ref name="embarcadero.com">{{cite web|url=http://blogs.embarcadero.com/abauer/2005/09/28/21433|title=The Oracle at Delphi|publisher=|accessdate=3 September 2015|archive-date=12 August 2015|archive-url=https://web.archive.org/web/20150812002619/http://blogs.embarcadero.com/abauer/2005/09/28/21433|url-status=dead}}</ref>
The majority of participants in the competition are assembler developers who often utilize processor-specific code and extra instruction sets, such as [[MMX]], [[SSE]], [[SSE2]], [[SSE3]], [[SSSE3]] and [[SSE4]].<ref>http://www.gerixsoft.com/blog/delphi/fastcode</ref>
 
The project was first hosted on Robert Lee's [[OptimalCode]] site, and its source code's home page is [https://fastcode.sourceforge.net/], last updated in 2008. The source code contains both the enhanced routines and the testing suites to benchmark the routines. In 2017, the benchmark routines for Move, FillChar and the memory manager have been ported for 64-bit, available at [https://github.com/maximmasiutin/FastCodeBenchmark].
The project enjoys the support of [[Embarcadero]] who recognizes the contributions of the FastCode team and incorporates their code into the codebase for Delphi.<ref>http://blogs.embarcadero.com/nickhodges/2006/11/27/29891</ref> The default [[memory manager]] for [[Embarcadero Delphi]], FastMM4, is the winner of the FastCode Memory Manager challenge.<ref>http://blogs.embarcadero.com/abauer/2005/09/28/21433</ref>
 
The project was first hosted on [[Robert Lee]]'s [[OptimalCode]] site, and its source code's current home is [http://fastcode.sourceforge.net/].
 
== Testing ==
The FastCode project puts a lot of effort into testing and focus is on providing very -high -quality software. Testing is split into two categories - testing for correctness and testing for speed.
 
The FastCode project puts a lot of effort into testing and focus is on providing very high quality software. Testing is split into two categories - testing for correctness and testing for speed.
 
=== Validation ===
Validation is done on all CPU'sCPUs from the target set and very often on other CPU'sCPUs and OS'sOSs ([[Windows XP]], [[Windows Vista]], [[Windows 7]] etc.) as well. Validation is done across many different function inputs, both normal usage cases and error usage cases. Validation is done against known correct values and against reference implementations such existing RTL functions.
 
=== Benchmarking ===
Benchmarking is done on all the CPU'sCPUs that are part of the current target set at the given time. These CPU'sCPUs have been or are part of target sets: ([[Intel Pentium 3]], [[Intel Pentium M]], [[Intel Pentium 4]], [[Intel Core]], [[Intel Core2Core 2]], [[AMD Athlon XP]], [[AMD Opteron]], [[AMD Phenom]]).
Great care has been taken to make the benchmarks stable and realistic. Especially the memory manager challenge benchmark was hard to get fair and memory manager usage logs were made from normal usage of real world applications, and then played back by the benchmark.
 
== Targets ==
Testing done on the entire targetset. A new targetset is decided each year from a poll where the FastCode community can vote. A targetset will typically consist of six CPUs, where four are from Intel and two are from AMD. This ratio has been selected to mimic the marketshares. In addition to these six CPU targets there are ten targets defined as a blend of the six CPUs. These ten targets are called computed targets and can be speed only or a combination of speed and size. The maximum allowed instruction set is different for each target. A target could be "IA32 size penalty" or "SSE2".
A targetset will typically consist of 6 CPU's, where 4 are from Intel and 2 are from AMD. This ratio has been selected to mimic the marketshares.
In addition to these 6 CPU targets there are 10 targets defined as a blend of the 6 CPU's. These 10 targets are called computed targets and can be speed only or a combination of speed and size. The maximum allowed instruction set is different for each target. A target could be "IA32 size penalty" or "SSE2".
The penalty for size is decided for each challenge by a poll.
 
== List of Challengeschallenges ==
The FastCode project has run the following challenges [httphttps://fastcode.sourceforge.net/]:
 
{{Div col|colscolwidth=322em}}
The FastCode project has run the following challenges [http://fastcode.sourceforge.net/]:
{{Div col|cols=3}}
*AES ([[Advanced Encryption Standard]])
*AnsiStringReplace (Replaces occurrences of a substring within a string.)
Line 40 ⟶ 38:
*CharPos (Searches for the first occurrence of a Char in a String. It returns the position of this occurrence.)
*CharPosIEx (Case insensitive search for the first occurrence of a Char in a String starting from an index passed as parameter. It returns the position of this occurrence.)
*CharPosEy (Searches for the n'th occurenceoccurrence of a Char in a string starting from an index passed as parameter. It returns the position of this occurrence.)
*CharPosRev (Searches for the last occurrence of a Char in a String. It returns the position of this occurrence.)
*CompareMem (Compares two blocks of memory.)
Line 96 ⟶ 94:
*UpperCase (Converts a string to uppercase)
*Val
{{Divdiv col end}}
 
== Contributions to Delphi RTL ==
FastCode functions included in the Delphi RTL:
 
*Delphi 2005: CompareText, Int64Div and FillChar.
*Delphi 2006:<ref>Long, Brian & Swart, Bob, "Borland Developer Studio 2006 Reviewed", The Delphi Magazine, Issue 124, December 2005</ref>: CompareText, Int64Div and FillChar, FastMM4 memory manager .<ref>http://blogs. name="embarcadero.com"/abauer/2005/09/28/21433</ref>
*Delphi 2007—Delphi XE: ArcCos, ArcSin, Power, PosEx, Move, Memory Manager, FillChar, Pos, __lldiv, LowerCase, UpperCase, CompareStr, CompareMem, CompareText, StrLen, StrCopy, StrComp.<ref>{{cite web|url=http://www.stevetrefethen.com/blog/CommunitycontributionsimproveDelphi2007RTLperformance.aspx|title=Community contributions improve Delphi 2007 RTL performance|publisher=|accessdate=3 September 2015|archive-url=https://web.archive.org/web/20160306225447/http://www.stevetrefethen.com/blog/community-contributions-improve-delphi-2007-rtl-performance|archive-date=6 March 2016}}</ref>
 
The ''Mastering Delphi'' books by Marco Cantu contains a chapter about FastCode listing the contributions to the Delphi RTL .<ref>{{cite web|url=http://www.marcocantu.com/md2005/UpdateDelphi2006_ch05.html|title=Mastering Delphi Update for Delphi 2006|publisher=|accessdate=3 September 2015}}</ref>
 
== The FastCode Library ==
 
All the challenge winners are included in the FastCode library (httphttps://fastcode.sourceforge.net/challenge_content/rtl_replcmnt_pkg.html). This library is [[Open-source software|open source]], released under the [[Mozilla Public License|MPL license]]. The library can be used in two ways: 1) Callingcalling functions directly., and 2) Usingusing the patching functionality.
 
When calling functions directly it is entirely up to the application developer to call the version of a function he thinks is fastest.
Line 115 ⟶ 113:
When using the patching functionality the library automatically detects the CPU type at application load, and uses this information to redirect all function calls to the FastCode winner function for that specific CPU.
 
== FastMM4 Memorymemory Managermanager ==
The FastMM memory manager used by Delphi and C++ Builder since 2006 is also the winner of a FastCode competition.<ref>Gabrijelcic, Primoz, "To Manage Memory", The Delphi Magazine, Issue 126, February 2006</ref> It replaced the standard memory manager of Delphi and is not only less prone to memory fragmentation, it also provides improved debugging possibilities like being able to report [[memory leaksleak]]s when the application is being closed,<ref>{{cite web|url=http://blog.marcocantu.com/blog/fastmm4.html|title=FastMM4|publisher=|accessdate=3 September 2015}}</ref>, detecting use after memory release or double releases.
 
FastMM4 is also used as memory manager for applications developed in Lazarus.<ref>{{cite web|url=https://books.google.com/books?id=WCrzCSuNfHoC&q=fastmm+delphi&pg=PA64|title=Lazarus Free Pascal|publisher=|accessdate=3 September 2015}}</ref>
 
FastMM4 is often listed as a "must have" tool for Delphi developers .<ref>{{cite web|url=http://delphi.wikia.com/wiki/Good_Tools_for_Delphi_Developers|title=Good Tools for Delphi Developers|work=Delphi Programming|accessdate=3 September 2015}}</ref>
FastMM4 is also used as memory manager for applications developed in Lazarus <ref>http://books.google.dk/books?id=WCrzCSuNfHoC&pg=PA64&lpg=PA64&dq=fastmm+delphi&source=bl&ots=nmf3lvxc0G&sig=mBWWTH_XN7QJIRmC2ChTlUuw3I8&hl=da&ei=yH85TfGmFcKRswaKqrDzBg&sa=X&oi=book_result&ct=result&resnum=7&ved=0CEgQ6AEwBji2Ag#v=onepage&q&f=false</ref>
 
Nexus DB comes with FastMM4 integration for leakchecking .<ref>{{cite web|url=http://www.nexusdb.com/support/index.php?q=node/10200|title=NexusDB|publisher=|accessdate=3 September 2015}}</ref>
FastMM4 is often listed as a "must have" tool for Delphi developers <ref>http://delphi.wikia.com/wiki/Good_Tools_for_Delphi_Developers</ref>
 
FastMM usage is documented in "The New Memory Manager In BDS 2006".<ref>{{cite web|url=http://edn.embarcadero.com/article/33416|title=The New Memory Manager In BDS 2006 - by Pierre le Riche|publisher=|accessdate=3 September 2015}}</ref>
Nexus DB comes with FastMM4 integration for leakchecking <ref>http://www.nexusdb.com/support/index.php?q=node/10200</ref>
 
== Applications Usingusing FastCode ==
An application developed in Delphi or C++ Builder will typically use the default memory manager which is FastMM4. FastCode functions in the RTL have been selected to be the most commnlycommonly used ones and an application will also typically use some of these, especially if any string handling is done. Most Delphi/C++ Builder applications will therefore use code developed by the FastCode project. Some examples are [[Skype]], [http[FL Studio]], and [[Embarcadero Technologies|Embarcadero]]’s own [[RAD Studio]]. [https://wwwhallvards.skypeblogspot.com/2007/05/use-full-fastmm-consider-donating.html Hallvard's blog] describes FastMM4 and Embarcaderowhy RADit Studiois being used as the memory manager in [http://www.theonlinetrader.com/ "The Online Trader"] application.
[http://hallvards.blogspot.com/2007/05/use-full-fastmm-consider-donating.html Hallvard's blog] describes FastMM4 and why it is being used as the memory manager in [http://www.theonlinetrader.com/ "The Online Trader"] application.
 
== References ==
Line 135 ⟶ 134:
[[Category:Computer libraries]]
[[Category:Programming contests]]
[[Category:Delphi (programming language)]]