Skip to content

Commit b9ddb8d

Browse files
committed
wip: perf guide
1 parent 73044e7 commit b9ddb8d

File tree

2 files changed

+104
-12
lines changed

2 files changed

+104
-12
lines changed

examples/official-site/performance.sql

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,21 @@ as opposed to writing imperative code in a backend programming language like Jav
2222
This declarative approach allows SQLPage to offer **optimizations** out of the box that are difficult or time-consuming
2323
to achieve in traditional web development stacks.
2424
25-
## Server-side rendering
25+
## Progressive server-side rendering
2626
2727
SQLPage applications are [server-side rendered](https://web.dev/articles/rendering-on-the-web),
28-
which means that the SQL queries are executed on the server, and the results are sent to the user''s browser
29-
as HTML, which allows it to start rendering the page as soon as the first byte is received.
28+
which means that the SQL queries are executed on the server, and the results are sent to the user''s browser as HTML.
3029
In contrast, many other web frameworks render the page on the client side, which means that the browser has to download
3130
some HTML, then download some JavaScript, then execute the JavaScript, then make more requests,
31+
wait for the database to produce a full result set,
3232
then process the responses before it can start rendering the actual data the user is interested in.
3333
This can lead to loading times that are several times longer than a SQLPage application.
3434
3535
### Streaming
3636
3737
SQLPage applications will often feel faster than even equivalent applications written even in alternative server-side rendering
3838
frameworks, because SQLPage streams the results of the SQL queries to the browser as soon as they are available.
39+
The user sees the start of the page even before the database has finished producing the last query results.
3940
4041
Most server-side rendering frameworks will first wait for all the SQL queries to finish, then render the page in memory
4142
on the server, and only then send the HTML webpage to the browser. If a page contains a long list of items, the user
@@ -51,7 +52,7 @@ an execution plan every time an user requests a page.
5152
5253
When an user loads a page, all SQLPage has to do is tell the database: "Hey, do you remember that query we talked about
5354
earlier? Can you give me the results for these specific parameters?". This is much faster than sending the whole SQL query
54-
string to the database every time.
55+
string to the database every time, especially for large complex queries that require heavy planning on the database side.
5556
5657
## Compiled templates
5758
@@ -87,16 +88,15 @@ interaction.
8788
8889
## Key Takeaways
8990
90-
SQLPage offers a radically different approach to web development,
91-
resolving the classical tension between performance and ease of use.
92-
93-
By leveraging a declarative approach, server-side rendering, and advanced optimization techniques, SQLPage enables:
94-
95-
* **Faster page loads**: Long loading times make your website feel sluggish and unresponsive, causing users to leave.
96-
* **Easier development**: Focus on writing SQL queries; all the heavy lifting is done for you.
97-
* **Cost effective**: SQLPage''s low CPU and memory usage means you can host your website extremely cheaply, even if it gets significant traffic.
91+
Performance is a key feature of SQLPage.
92+
Its architecture allows you to build fast websites without having to implement advanced optimizations yourself.
9893
9994
## Ready to get started?
10095
10196
[Build your fast, secure, and beautiful website](/your-first-sql-website) with SQLPage today!
97+
98+
## Already a SQLPage developer ?
99+
100+
Have a look at our [performance guide](/blog?post=Performance+Guide) to learn the best practices to leverage
101+
all the features that will make your site faster.
102102
' as contents_md;
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
2+
INSERT INTO blog_posts (title, description, icon, created_at, content)
3+
VALUES
4+
(
5+
'Performance Guide',
6+
'Concrete advice on how to make your SQLPage webapp fast',
7+
'bolt',
8+
'2025-10-31',
9+
'
10+
# Performance Guide
11+
12+
SQLPage is [optimized](/performance)
13+
to allow you to create web pages that feel snappy.
14+
This guide contains advice on how to ensure your users never wait
15+
behind a blank screen waiting for your pages to load.
16+
17+
A lot of the advice here is not specific to SQLPage, but applies
18+
to making SQL queries fast in general.
19+
If you are already comfortable with SQL performance optimization, feel free to jump right to
20+
the second part of the quide: *SQLPage-specific advice*.
21+
22+
## Make your queries fast
23+
24+
The best way to ensure your SQLPage webapp is fast is to ensure your
25+
database is well managed and your SQL queries are well written.
26+
We''ll go over the most common database performance pitfalls so that you know how to avoid them.
27+
28+
### Choose the right database schema
29+
30+
#### Normalize (but not too much)
31+
32+
Your database schema should be made so that one piece of information
33+
is stored in only one place in the database.
34+
For instance, if you are modelling sales that happen in stores, the sales table should
35+
contain a foreign key to another table named stores.
36+
This way, when you need to display the list of stores in your application, you don''t have to
37+
run a slow `select distinct store from sales`, that would have to go through your millions of sales
38+
(*even if you have an index on the store column*),
39+
40+
### Use database indices
41+
42+
### Use (materialized) views
43+
44+
### Query performance debugging
45+
46+
## SQLPage-specific advice
47+
48+
The best way to make your SQLPage webapp fast is to make your queries fast.
49+
Sometimes, you just don''t have control over the database, and have to run slow queries.
50+
This section will help you minimize the impact to your users.
51+
52+
### Order matters
53+
54+
SQLPage executes the queries in your `.sql` files in order.
55+
It does not start executing a query before the previous one has returned all its results.
56+
So, if you have to execute a slow query, put it as far down in the page as possible.
57+
58+
#### No heavy computation before the shell
59+
60+
Every user-facing page in a SQLPage site has a [shell](/components?component=shell).
61+
62+
The first queries in any sql file (all the ones that come before the [])
63+
64+
#### Set variables just above their first usage
65+
66+
### Avoid recomputing the same data multiple times
67+
68+
### Reduce the number of queries
69+
70+
### Lazy loading
71+
72+
Use the card and modal components to load data lazily.
73+
74+
### Database connections
75+
76+
SQLPage uses connection pooling: it keeps multiple database connections opened,
77+
and reuses them for consecutive requests. When it does not receive requests for a long time,
78+
it closes idle connection. When it receives many requests, it opens new connection,
79+
but never more than the value specified by `max_database_pool_connections` in its
80+
[configuration](https://github.com/sqlpage/SQLPage/blob/main/configuration.md).
81+
You can increase the value of that parameter if your website has many concurrent users and your
82+
database is configured to allow opening many simultaneous connections.
83+
84+
### SQLPage performance debugging
85+
86+
When `environment` is set to `development` in its [configuration](https://github.com/sqlpage/SQLPage/blob/main/configuration.md),
87+
SQLPage will include precise measurement of the time it spends in each of the steps it has to go through before starting to send data
88+
back to the user''s browser. You can visualize that performance data in your browser''s network inspector.
89+
90+
You can set the `RUST_LOG` environment variable to `sqlpage=debug` to make SQLPage
91+
print detailed messages associated with precise timing for everything it does.
92+
');

0 commit comments

Comments
 (0)