Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Use indexes instead of filter() for efficient database queries
.claude/skills/kunanonj-cursor-plugin-convex-rule-query-optimization/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-09 | ✗→✓ | ▲ Improved | -23% | 0% |
| case-01 | ✓→✓ | = Same ✓ | -11% | 0% |
| case-02 | ✓→✓ | = Same ✓ | 22% | 0% |
| case-03 | ✓→✓ | = Same ✓ | -12% | 0% |
| case-04 | ✓→✓ | = Same ✓ | -29% | 0% |
Avoid using .filter() on database queries. Instead, use indexed queries with .withIndex() or filter in TypeScript after collecting results.
Using .filter() on queries performs a full table scan, which becomes slow as your data grows. Indexes provide fast lookups.
Bad:
typescriptconst user = await ctx.db .query("users") .filter(q => q.eq(q.field("email"), email)) .first();
Good:
typescript// In schema.ts export default defineSchema({ users: defineTable({ email: v.string(), name: v.string(), }).index("by_email", ["email"]), }); // In your function const user = await ctx.db .query("users") .withIndex("by_email", q => q.eq("email", email)) .first();
If you must filter by a field that doesn't warrant an index:
typescriptconst allUsers = await ctx.db.query("users").collect(); const filtered = allUsers.filter(user => user.age > 18);
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-01 | pass→pass | 4,858 | 3,078 | -37% | 1 | 1 | 0% | 1,169 | 1,038 | -11% | 0 | 0 | — |
case-02 | pass→pass | 5,614 | 2,451 | -56% | 1 | 1 | 0% | 707 | 862 | +22% | 0 | 0 | — |
case-03 | pass→pass | 4,648 | 3,085 | -34% | 1 | 1 | 0% | 1,052 | 930 | -12% | 0 | 0 | — |
case-04 | pass→pass | 5,707 | 3,159 | -45% | 1 | 1 | 0% | 1,333 | 942 | -29% | 0 | 0 | — |
case-05 | pass→pass | 6,111 | 3,097 | -49% | 1 | 1 | 0% | 1,374 | 873 | -36% | 0 | 0 | — |
case-06 | pass→pass | 7,517 | 5,892 | -22% | 1 | 1 | 0% | 1,732 | 1,506 | -13% | 0 | 0 | — |
case-07 | pass→pass | 3,643 | 2,910 | -20% | 1 | 1 | 0% | 783 | 939 | +20% | 0 | 0 | — |
case-08 | pass→pass | 4,792 | 3,124 | -35% | 1 | 1 | 0% | 1,047 | 1,028 | -2% | 0 | 0 | — |
case-09 | fail→pass | 4,001 | 2,114 | -47% | 1 | 1 | 0% | 902 | 699 | -23% | 0 | 0 | — |
case-10 | pass→pass | 5,379 | 3,036 | -44% | 1 | 1 | 0% | 1,246 | 1,024 | -18% | 0 | 0 | — |
case-11 | pass→pass | 2,901 | 2,432 | -16% | 1 | 1 | 0% | 696 | 836 | +20% | 0 | 0 | — |
case-12 | pass→pass | 6,977 | 3,808 | -45% | 1 | 1 | 0% | 1,618 | 1,237 | -24% | 0 | 0 | — |
case-13 | pass→pass | 5,493 | 3,515 | -36% | 1 | 1 | 0% | 1,091 | 1,090 | -0% | 0 | 0 | — |
case-14 | pass→pass | 6,586 | 3,343 | -49% | 1 | 1 | 0% | 1,517 | 940 | -38% | 0 | 0 | — |
case-15 | pass→pass | 4,975 | 2,512 | -50% | 1 | 1 | 0% | 1,148 | 838 | -27% | 0 | 0 | — |
case-16 | pass→pass | 3,881 | 3,280 | -15% | 1 | 1 | 0% | 912 | 972 | +7% | 0 | 0 | — |
case-17 | pass→pass | 5,492 | 3,409 | -38% | 1 | 1 | 0% | 1,308 | 916 | -30% | 0 | 0 | — |
case-18 | pass→pass | 4,674 | 2,664 | -43% | 1 | 1 | 0% | 942 | 866 | -8% | 0 | 0 | — |
case-19 | pass→pass | 4,610 | 3,309 | -28% | 1 | 1 | 0% | 1,097 | 929 | -15% | 0 | 0 | — |
case-20 | pass→pass | 3,842 | 3,350 | -13% | 1 | 1 | 0% | 878 | 1,000 | +14% | 0 | 0 | — |
case-21 | pass→pass | 4,181 | 2,789 | -33% | 1 | 1 | 0% | 1,000 | 887 | -11% | 0 | 0 | — |
case-22 | pass→pass | 2,824 | 2,436 | -14% | 1 | 1 | 0% | 622 | 701 | +13% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted. The headline lift of +5 percentage points is the difference between those two pass rates over the 22 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.