Documentation Source Text

Check-in [edc057616f]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add the "Why Is SQLite Coded In C" document.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: edc057616f29417ee22d8788993644b0e7237ff66f844a3b04f24e799f59f078
User & Date: drh 2017-05-15 17:07:07
Context
2017-05-22
13:36
Update the speed-and-size spreadsheet. check-in: 5bed01e6bb user: drh tags: trunk
2017-05-15
17:07
Add the "Why Is SQLite Coded In C" document. check-in: edc057616f user: drh tags: trunk
2017-05-12
21:05
Hyperlinks to the faster-than-the-filesystem report from the two application-file-format articles. check-in: a79b7fc8f1 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to pages/fasterthanfs.in.

     1      1   <title>35% Faster Than The Filesystem</title>
     2         -<tcl>hd_keywords {faster than the filesystem}</tcl>
            2  +<tcl>hd_keywords {faster than the filesystem} \
            3  +   {35% Faster Than The Filesystem}</tcl>
     3      4   
     4      5   <table_of_contents>
     5      6   
     6      7   <h1>Summary</h1>
     7      8   
     8      9   <p>Small blobs (for example, thumbnail images)
     9     10   can be read out of an SQLite database about 35% faster

Added pages/whyc.in.

            1  +<title>Why Is SQLite Coded In C</title>
            2  +
            3  +<table_of_contents>
            4  +
            5  +<h1>C Is Best</h1>
            6  +
            7  +<p>
            8  +Since its inception on 2000-05-29, SQLite has been implemented in generic C.
            9  +C was and continues to be the best language for implementing a software
           10  +library like SQLite.  There are no plans to recode SQLite in any other
           11  +programming language anytime soon.
           12  +
           13  +<p>
           14  +The reasons why C is the best language to implement SQLite include:
           15  +
           16  +
           17  +<ul>
           18  +<li> Performance
           19  +<li> Compatibility
           20  +<li> Low-dependency
           21  +<li> Stability
           22  +</ul>
           23  +
           24  +<h2>Performance</h2>
           25  +
           26  +<p>An intensively used low-level library like SQLite needs to be fast.
           27  +(And SQLite is fast, see [Internal Versus External BLOBs] and
           28  +[35% Faster Than The Filesystem] for example.)
           29  +
           30  +<p>C is a great language for writing fast code.  C is sometimes
           31  +described as "portable assembly language".  It enables to developers
           32  +to code as close to the underlying hardware as possible while still
           33  +remaining portable across platforms.
           34  +
           35  +<p>Other programming languages sometimes claim to be "as fast as C".
           36  +But no other language claims to be faster than C for general-purpose
           37  +programming, because none are.
           38  +
           39  +<h2>Compatibility</h2>
           40  +
           41  +<p>Nearly all systems have the ability to call with libraries
           42  +written in C.  This is not true of other implementation languages.
           43  +
           44  +<p>So, for example, Android applications written in Java are able to
           45  +invoke SQLite (through an adaptor).  Maybe it would have been more
           46  +convenient for Android if SQLite had been coded in Java as that would
           47  +make the interface simpler.  However, on iPhone applications are coded
           48  +in Objective-C or Swift, neither of which have the ability to call
           49  +libraries written in Java.  Thus, SQLite would be unusable on iPhones
           50  +had it been written in Java.
           51  +
           52  +<h2>Low-Dependency</h2>
           53  +
           54  +<p>Libraries written in C doe not have a huge run-time dependency.
           55  +In its minimum configuration, SQLite requires only the following
           56  +routines from the standard C library:
           57  +
           58  +<center>
           59  +<table border=0>
           60  +<tr>
           61  +<td valign="top">
           62  +<ul>
           63  +<li> memcmp()
           64  +<li> memcpy()
           65  +<li> memmove()
           66  +<li> memset()
           67  +</ul>
           68  +</td>
           69  +<td>&nbsp;&nbsp;&nbsp;</td>
           70  +<td valign="top">
           71  +<ul>
           72  +<li> strcmp()
           73  +<li> strlen()
           74  +<li> strncmp()
           75  +</ul>
           76  +</td>
           77  +</tr>
           78  +</table>
           79  +</center>
           80  +
           81  +<p>
           82  +In a more complete build, SQLite also uses library routines like
           83  +malloc() and free() and operating system interfaces for opening, reading,
           84  +writing, and closing files.  But even then, the number of dependences
           85  +is very small.  Other "modern" language, in contrast, often require
           86  +multi-megabyte runtimes loaded with thousands and thousands of interfaces.
           87  +
           88  +<h2>Stability</h2>
           89  +
           90  +<p>
           91  +The C language is old and boring.
           92  +It is a well-known and well-understood language.
           93  +This is exactly what one wants when developing a module like SQLite.
           94  +Writing a small, fast, and reliable database engine is hard enough as it
           95  +is without the implementation language changing out from under you with
           96  +each update to the implementation language specification.