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.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: edc057616f29417ee22d8788993644b0e7237ff66f844a3b04f24e799f59f078
User & Date: drh 2017-05-15 17:07:07.087
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
Unified Diff Ignore Whitespace Patch
Changes to pages/fasterthanfs.in.
1
2

3
4
5
6
7
8
9
<title>35% Faster Than The Filesystem</title>
<tcl>hd_keywords {faster than the filesystem}</tcl>


<table_of_contents>

<h1>Summary</h1>

<p>Small blobs (for example, thumbnail images)
can be read out of an SQLite database about 35% faster

|
>







1
2
3
4
5
6
7
8
9
10
<title>35% Faster Than The Filesystem</title>
<tcl>hd_keywords {faster than the filesystem} \
   {35% Faster Than The Filesystem}</tcl>

<table_of_contents>

<h1>Summary</h1>

<p>Small blobs (for example, thumbnail images)
can be read out of an SQLite database about 35% faster
Added pages/whyc.in.
































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<title>Why Is SQLite Coded In C</title>

<table_of_contents>

<h1>C Is Best</h1>

<p>
Since its inception on 2000-05-29, SQLite has been implemented in generic C.
C was and continues to be the best language for implementing a software
library like SQLite.  There are no plans to recode SQLite in any other
programming language anytime soon.

<p>
The reasons why C is the best language to implement SQLite include:


<ul>
<li> Performance
<li> Compatibility
<li> Low-dependency
<li> Stability
</ul>

<h2>Performance</h2>

<p>An intensively used low-level library like SQLite needs to be fast.
(And SQLite is fast, see [Internal Versus External BLOBs] and
[35% Faster Than The Filesystem] for example.)

<p>C is a great language for writing fast code.  C is sometimes
described as "portable assembly language".  It enables to developers
to code as close to the underlying hardware as possible while still
remaining portable across platforms.

<p>Other programming languages sometimes claim to be "as fast as C".
But no other language claims to be faster than C for general-purpose
programming, because none are.

<h2>Compatibility</h2>

<p>Nearly all systems have the ability to call with libraries
written in C.  This is not true of other implementation languages.

<p>So, for example, Android applications written in Java are able to
invoke SQLite (through an adaptor).  Maybe it would have been more
convenient for Android if SQLite had been coded in Java as that would
make the interface simpler.  However, on iPhone applications are coded
in Objective-C or Swift, neither of which have the ability to call
libraries written in Java.  Thus, SQLite would be unusable on iPhones
had it been written in Java.

<h2>Low-Dependency</h2>

<p>Libraries written in C doe not have a huge run-time dependency.
In its minimum configuration, SQLite requires only the following
routines from the standard C library:

<center>
<table border=0>
<tr>
<td valign="top">
<ul>
<li> memcmp()
<li> memcpy()
<li> memmove()
<li> memset()
</ul>
</td>
<td>&nbsp;&nbsp;&nbsp;</td>
<td valign="top">
<ul>
<li> strcmp()
<li> strlen()
<li> strncmp()
</ul>
</td>
</tr>
</table>
</center>

<p>
In a more complete build, SQLite also uses library routines like
malloc() and free() and operating system interfaces for opening, reading,
writing, and closing files.  But even then, the number of dependences
is very small.  Other "modern" language, in contrast, often require
multi-megabyte runtimes loaded with thousands and thousands of interfaces.

<h2>Stability</h2>

<p>
The C language is old and boring.
It is a well-known and well-understood language.
This is exactly what one wants when developing a module like SQLite.
Writing a small, fast, and reliable database engine is hard enough as it
is without the implementation language changing out from under you with
each update to the implementation language specification.