D1 Latency

I am truly excited about D1. It was fun playing around with it. I think I like idea a lot.

While playing around with D1, somehow I am experiencing high latency for this simple code

async fetch(request: Request): Promise<Response> {
    const url = new URL(request.url);

    if (url.pathname === '/fetchdb') {
      const stmt = env.DB1.prepare("SELECT id, value FROM places WHERE id = ?");
      const results = await stmt.bind('1').first();
      return new Response(JSON.stringify(results['id']));

    // Default
    return new Response('Hello world');

The database only contain 1 table, 1 row with 2 columns (id, value)

Accessing “/” would always fast (40ms)

But accessing “/fetchdb” would always slow (avg. 452ms)

Is there any thought on this?

It’s an alpha - it hasn’t had all the performance tuning you’d expect and there also isn’t any read replicas which are on the roadmap yet.

1 Like