Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-4570

New TypeScript generator optimized for size

    XMLWordPrintableJSON

Details

    Description

      I propose to add a new compiler generating native typescript code with the following goals:

      • Using promise only (no direct callback)
      • Reducing the generated code to the minimum
      • Fully typed code to avoid misuse of generated code
      • Initially geared toward web-browser usage and not nodejs

      My understanding is that the usual generator flow is not ideal for javascript because:

      • The advantage of using a streaming parser is lost (cf. initial JSON.parse)
      • It's not clear if we gain much by doing a streaming write vs. a JSON.stringify
      • The usual transports available (xhr, websocket) don't mix well with streaming
      • The 'speed first' focus is not the first concern I encountered using thrift in a browser environment. I am usually more concerned by final code bundle size than the speed at which the messages are serialized.

      So I wrote a prototype which produces a quite different kind of code compared to the js generator and the results are interesting. On a set of existing thrift interfaces, here is the difference in size (fully compressed/minified and including respective libraries):

      • Using standard js generator: 484 Kb
      • Using my prototype ts generator: 184 Kb

      It's around a 1:2.5 ratio. Some files have up to a 1:5 ratio.

      But there is no magic. There is of course a potential performance penalty when moving more serialization/deserialization code in a shared library, which should be fully evaluated. Also the code needs to be tested and further improved. It's still rough at this stage.

      Here attached is the output generated for the SmallTest example found in the thrift tests folder.

      I'll open a pull request if there is interest in this direction.

      Attachments

        1. SmallService.ts
          4 kB
          Antony Ducommun
        2. SmallTest_types.ts
          6 kB
          Antony Ducommun
        3. SmallTest.thrift
          2 kB
          Antony Ducommun
        4. thrift.ts
          28 kB
          Antony Ducommun

        Activity

          People

            Unassigned Unassigned
            nitro.tm Antony Ducommun
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: