Optimize prepared statements?

I was looking at profiles of an application using modernc.org/sqlite and noticed it was spending much of its CPU time in SQL parsing.

Looking at the code, it seems like Prepare doesn't actually call into sqlite3 prepare APIs at all:

// PrepareContext implements driver.ConnPrepareContext
func (c *conn) PrepareContext(ctx context.Context, query string) (ds driver.Stmt, err error) {
  if dmesgs {
    defer func() {
      dmesg("conn %p, ctx %p, query %q: (driver.Stmt %v, err %v)", c, ctx, query, ds, err)
    }()
  }
  return c.prepare(ctx, query)
}
..
func (c *conn) prepare(ctx context.Context, query string) (s driver.Stmt, err error) { //TODO use ctx
  return newStmt(c, query)
}
...
func newStmt(c *conn, sql string) (*stmt, error) {
  p, err := libc.CString(sql)
  if err != nil {
    return nil, err
  }
  stm := stmt{c: c, psql: p}
  return &stm, nil
}

I couldn't find an existing open issue about this, so filing this one.

Any warnings before I attempt to implement this?

parse.png

Edited by Brad Fitzpatrick