Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preview feature feedback: jsonProtocol #18095

Closed
janpio opened this issue Feb 25, 2023 · 75 comments
Closed

Preview feature feedback: jsonProtocol #18095

janpio opened this issue Feb 25, 2023 · 75 comments
Labels
kind/feedback Issue for gathering feedback. team/client Issue for team Client. topic: jsonProtocol topic: performance topic: previewFeatures Issue touches on an preview feature flag
Milestone

Comments

@janpio
Copy link
Member

janpio commented Feb 25, 2023

Our new Json Protocol is in early preview since 4.11.0.

During performance investigations and optimizations, we noticed that the existing protocol implementation using GraphQL added a CPU and memory overhead that was especially noticeable for larger Prisma schemas. Therefore, we found an alternative way to express our queries without needing that overhead: JSON.

To try out the new protocol, enable the jsonProtocol Preview feature in your Prisma schema:

generator client {
  provider        = "prisma-client-js"  
  previewFeatures = ["jsonProtocol"]
}

Regenerate Prisma Client to use the new JSON protocol.

For environments or situations where it is not viable to enable the Preview feature flag to your Prisma schema file, we also added an environment variable that you can use to force the use of the JSON Protocol Preview feature: PRISMA_ENGINE_PROTOCOL=json.

Note: This is an early Preview feature with a significant limitation: Invalid input to Prisma Client will throw unpolished, internal errors that are less descriptive and user-friendly than our usual ones. We intend to improve these future releases. Using it with Data Proxy and Prisma Data Platform currently also leads to errors.

We expect using jsonProtocol to improve Prisma Client's startup performance and memory usage significantly. This will likely have a more significant impact on applications with larger Prisma schemas.

We would appreciate your feedback on this feature on the following particularly:

  1. Does using this preview feature introduce any regressions or problems in your application?
  2. If not, how does it influence the performance of your application? Can you share before and after measurements?

For feedback, please comment on this issue.


Please share your feedback about the jsonProtocol functionality released in v4.11.0 in this issue.

  • If you encounter a bug, please open a bug report in this repo.
  • If the feature is working well for you, please share this in a comment below or leave a 👍 on this issue.
  • If you have any questions, don't hesitate to ask them in the Prisma Slack community
@janpio
Copy link
Member Author

janpio commented Mar 3, 2023

Two things we discovered:

  1. Using Prisma Client for Data Proxy with jsonProtocol currently sometimes does not lead to good results. We are investigating.
  2. Uploading a Prisma schema with jsonProtocol to Prisma Data Platform currently can lead to error messages in Data Browser and Query Console. We will update (but then might be blocked by 1)

@mmmeff
Copy link

mmmeff commented Mar 5, 2023

The lack of bug reports is really indicative of the quality of the release. Thanks, Prisma devs!

@janpio
Copy link
Member Author

janpio commented Mar 5, 2023

Thanks 😆 The team will love to hear that.

Note the linked issues #18200 though, we seem to have missed a few details around enums.

And I honestly hope we will get a few "I measured, and this is now x% faster" messages...

@trentonsnyder
Copy link

@janpio I haven't done a very thorough analysis and my app still needs a lot of tuning but at first glance I'm seeing some pretty decent improvements in performance in Vercel.
I'm using a SQL Server DB with ~8,700 line schema file.

Some observations on one function:

Without "jsonProtocol" I was seeing ~790MB memory usage running upwards of 10 seconds on cold starts.
With "jsonProtocol" I'm seeing ~330MB memory usage and upwards of 6 seconds on cold starts.

@pheuter

This comment was marked as outdated.

@janpio

This comment was marked as outdated.

@pheuter

This comment was marked as outdated.

@semoal

This comment was marked as outdated.

@michaelhays
Copy link

Just wanted to report that enabling jsonProtocol reduced our cold starts on Vercel from ~8.5 seconds to ~4.5 seconds! With no issues found so far. 1,500 line schema.prisma file.

Nice work Prisma team :)

@SevInf

This comment was marked as outdated.

@SevInf

This comment was marked as outdated.

@yharaskrik

This comment was marked as outdated.

@SevInf

This comment was marked as outdated.

@tavindev
Copy link

tavindev commented Apr 6, 2023

Enabling jsonProtocol (v4.12.0) reduced RAM usage by ~55% in my case

@SevInf

This comment was marked as outdated.

@janpio

This comment was marked as outdated.

@shmuelsochet

This comment was marked as resolved.

@janpio

This comment was marked as outdated.

@yharaskrik
Copy link

When I am testing this out locally I am not seeing a change in memory usage, I am setting the previewFeatures to include jsonProtocol and then spin up my app with and without the preview feature, in both cases its about 290MB Startup and 238MB Idle, this is within a Nest server and loads 2 different schemas one for mongo (~1600 lines including comments, 40 Models), and one for postgres (~3800 lines and 133 Models).

@andresribeiro
Copy link

When I am testing this out locally I am not seeing a change in memory usage, I am setting the previewFeatures to include jsonProtocol and then spin up my app with and without the preview feature, in both cases its about 290MB Startup and 238MB Idle, this is within a Nest server and loads 2 different schemas one for mongo (~1600 lines including comments, 40 Models), and one for postgres (~3800 lines and 133 Models).

are u running "prisma generate" after changing?

@yharaskrik
Copy link

When I am testing this out locally I am not seeing a change in memory usage, I am setting the previewFeatures to include jsonProtocol and then spin up my app with and without the preview feature, in both cases its about 290MB Startup and 238MB Idle, this is within a Nest server and loads 2 different schemas one for mongo (~1600 lines including comments, 40 Models), and one for postgres (~3800 lines and 133 Models).

are u running "prisma generate" after changing?

I did yes. I can try it again though and just triple check. (I actually tried with the env var first but didn't see a change so then tried using the previewFeatures)

I was running the server with PRISMA_ENGINE_PROTOCOL=json node main.js

@SevInf
Copy link
Contributor

SevInf commented May 22, 2023

@trevorr

We're also getting the "Invalid time value" error. While I understand that the JSON protocol is being stricter, the issue is that I can't tell where it's happening because the call stack is not useful. Here's the output from a failed Jest test:

Could you try 4.15.0-dev.61 snapshot version? We've improved error message for this case (as well as ensured it happens for GraphQL protocol too) and now you should see the location of this error.

@SevInf

This comment was marked as outdated.

@SevInf
Copy link
Contributor

SevInf commented May 22, 2023

@yharaskrik
Could you run your script with DEBUG=prisma:* env var and ensure JSON protocol is really used during startup? There should be "protocol json" message during new PrismaClient() call, like on a screenshot here.

@yharaskrik
Copy link

@yharaskrik Could you run your script with DEBUG=prisma:* env var and ensure JSON protocol is really used during startup? There should be "protocol json" message during new PrismaClient() call, like on a screenshot here.

Ok I tried again and checked the protocol in the debug messages (measurements in MB)

JSON
237-295

Graphql
245-302

@yharaskrik
Copy link

@yharaskrik Could you run your script with DEBUG=prisma:* env var and ensure JSON protocol is really used during startup? There should be "protocol json" message during new PrismaClient() call, like on a screenshot here.

Ok I tried again and checked the protocol in the debug messages (measurements in MB)

JSON 237-295

Graphql 245-302

Did some additional measuring with and without Prisma with the API idling:

Without prisma Idle at: 161MB
With prisma (json) idle at: 225MB
With prisma (graphql) idle at: 227MB

So Prisma adds about 65MB regardless of protocol.

pjeweb added a commit to alveusgg/alveusgg that referenced this issue May 27, 2023
@2coo
Copy link

2coo commented May 30, 2023

Hello, I have migrated from sequelize and sequelize-typescript to prisma recently, and so far I am loving it for the most part! I recorded a video of me using web scraping with and without jsonProtocol and have noticed a noticeable performance increase. The database the code is reading and writing from has ~175MB worth data.

foodflation_scraper_jsonDecoder-2023-05-07_16.49.00.mp4
foodflation_scraper_jsonDecoder-2023-05-07_16.23.18.mp4
You can see code here and here

@destroyer22719

In your two videos, they are almost equal, even I didn't see a 2, 3 seconds speed difference

pjeweb added a commit to alveusgg/alveusgg that referenced this issue May 30, 2023
pjeweb added a commit to alveusgg/alveusgg that referenced this issue Jun 3, 2023
pjeweb added a commit to alveusgg/alveusgg that referenced this issue Jun 8, 2023
pjeweb added a commit to alveusgg/alveusgg that referenced this issue Jun 10, 2023
@perenstrom
Copy link

perenstrom commented Jun 21, 2023

I've tested a bit now with an example dataset I found, quite few models, quite few rows in the schema. But I went from ~4500ms to ~500ms in cold start times on Vercel serverless (NextJS API functions). So it cut about 90% of the time. Great job, will continue to explore!

EDIT: Unfortunately, this seems to just have been me not waiting enough for it to become a cold start. Now I'm getting ~4000ms startup again. So an improvement, just not very large. And to be fair, trying cold start times without any prisma calls is still really slow.

@immjs
Copy link

immjs commented Jun 21, 2023

We're evaluating jsonProtocol with Prisma 4.14 on a large schema (227 models, 7800 non-comment schema lines). We're getting a number of integration test failures with "invalid create invocation". The cause seems to be using the UncheckedCreateInput form but Prisma expecting CreateInput:

Invalid `prisma.contact.create()` invocation:

    {
      data: {
        firstName: "Hayden",
        lastName: "Jast",
        organizationId: "0290f094-69aa-4e87-a7c0-1f208a640286",
    +   organization: {
    +     create: OrganizationCreateWithoutContactsInput | OrganizationUncheckedCreateWithoutContactsInput,
    +     connectOrCreate: OrganizationCreateOrConnectWithoutContactsInput,
    +     connect: OrganizationWhereUniqueInput
    +   }
      }
    }

    Argument `organization` is missing.

This type checks fine based on this generated type:

  export type ContactUncheckedCreateInput = {
    id?: string
    organizationId: string
    firstName?: string | null
    lastName?: string | null
    ...

(Sorry, quote replied to the wrong message)

Did you figure out a solution to this one? I am experiencing the same issue

Invalid `prisma.convo.create()` invocation:
{
  data: {
    subject: "a",
    interlocutors: "[\"----\"]",
    folderId: "cliebhdly0002me088n3nxe3c",
    latest: new Date("2023-06-21T16:09:59.874Z"),
+   folder: {
+     create: FolderCreateWithoutConvosInput | FolderUncheckedCreateWithoutConvosInput,
+     connectOrCreate: FolderCreateOrConnectWithoutConvosInput,
+     connect: FolderWhereUniqueInput
+   }
  }
}
Argument `folder` is missing.

@johnjcsmith
Copy link

johnjcsmith commented Jun 27, 2023

Hello,

We have been testing jsonProtocol with Prisma 4.14.1 and have seen some instances of total memory usage dropping by 50%. Amazing work!

We have run into one "issue":
When filtering on JSON object properties, we had some Prisma code which looks like the following:

await prisma.foo.findMany({
  where: {
    nestedJsonObject: {
      path: 'bar',
      equals: 'baz',
    },
  },
})

Which started to emit the following error after enabling jsonProtocol:

Argument `path`: Invalid value provided. Expected String[], provided String.

We have since updated path to a string[] as per the docs.

My understanding is that this is likely the intended behaviour. Just flagging that it does appear to have become stricter with the new protocol.

@Jolg42 Jolg42 added this to the 5.0.0 milestone Jul 6, 2023
@janpio
Copy link
Member Author

janpio commented Jul 7, 2023

Correct @johnjcsmith, this is one of multiple changes to the "array shortcuts" that we did to clean up our APIs. We will introduce these as breaking changes in Prisma 5 when we make jsonProtocol GA and available by default. Good to hear the change was a simple one for you. Thanks!

@Jolg42
Copy link
Member

Jolg42 commented Jul 11, 2023

Thank you everyone for the feedback 🙌🏼

We’re thrilled to announce that the jsonProtocol Preview feature is now Generally Available. You can now remove the Preview feature flag from your schema after upgrading. We made the JSON-based wire protocol the default protocol used for communication between Prisma Client and the query engine.

We introduced this feature in version 4.11.0 to improve Prisma’s performance. Previously, Prisma used a GraphQL-like protocol to communicate between Prisma Client and the query engine. Applications with larger schemas had higher CPU and memory consumption compared to smaller schemas which created a performance bottleneck.

The JSON-based wire protocol improves efficiency when Prisma Client is communicating with the query engine.

If you want to learn more about the performance improvements that are bundled with Prisma 5, including the JSON-based protocol, we recommend giving Prisma 5: Faster by Default a read.

See Prisma 5.0.0 release notes.

@Jolg42 Jolg42 closed this as completed Jul 11, 2023
@ayvanov
Copy link

ayvanov commented Jul 12, 2023

If you want to learn more about the performance improvements that are bundled with Prisma 5, including the JSON-based protocol, we recommend giving Prisma 5: Faster by Default a read.

Link is 404?

@Jolg42
Copy link
Member

Jolg42 commented Jul 12, 2023

@ayvanov Sorry about that, stay tuned, the blog post is not published yet but should be coming very soon!

@Jolg42
Copy link
Member

Jolg42 commented Jul 12, 2023

@ayvanov Here it is https://www.prisma.io/blog/prisma-5-f66prwkjx72s ✍🏼

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feedback Issue for gathering feedback. team/client Issue for team Client. topic: jsonProtocol topic: performance topic: previewFeatures Issue touches on an preview feature flag
Projects
None yet
Development

No branches or pull requests