question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Performance tweak for 1.0

See original GitHub issue

Since version 1.0.0-beta.6 I drop the internal type converter into dedicated type converter package TypedConverter. There are reason behind why it should have dedicated type converter VS uses existing converter such as JOI which is mature and fast.

  • TypedConverter designed to use TypeScript metadata/reflection so Framework able to convert request information (body, header, params) into appropriate controller parameter type.
  • Framework require an “extension point” to do some extra process on each conversion such as Validating the value using existing validator package, or User created validation.
  • Joi is a validation library with conversion ability created for JS user, It uses schema configuration vs read from TypeScript reflection.
  • Joi validation is synchronous, Plumier provided user to create their own custom validation which require async operation such as access database etc.

Since v1.0.0-beta.6 overall performance dropped about 3% on simple GET request, for complex request with request body it drops even more performance and under express performance point.

image

Performance Target

Drop performance target should be at most 10% under KOA performance, both for simple GET and complex POST with validation.

Changes

Current conversion logic on TypedConverter will be changed. It will follow how JOI conversion work. It compile Type into optimized AST for conversion, then use the AST to convert the value into appropriate type: example


class Address {
    constructor(
        public city:string,
        public state:string,
        public address:string
    ){}
}
class MyDomain {
    constructor(
        public name:string,
        public birthDate:Date,
        public isDecased:boolean,
        public address: Address
    ){}
}

If asked to convert value into above type, TypedConverter will compile above type into AST below:

{
    kind: "Object",
    type: MyDomain,
    properties: [
        {
            kind: "Primitive",
            type: String,
            converter: stringConverter,
            name: "name"
        },
        {
            kind: "Primitive",
            type: Date,
            converter: dateConverter,
            name: "birthDate"
        },
        {
            kind: "Primitive",
            type: Boolean,
            converter: booleanConverter,
            name: "isDeceased"
        },
        {
            kind: "DeferredObject",
            type: Address,
            name: "address"
        }
    }
}

Each properties defined with AST Node with some classification kind based on its data type. For nested object, the property definition deferred until its ready to convert it will be transformed during conversion using cache to guarantee the speed. This deferred behavior is part of optimization due to value of the property can be null so its doesn’t waste time during AST transformer.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7

github_iconTop GitHub Comments

2reactions
ktutnikcommented, Jul 3, 2019

PR #158 implemented some performance improvement, it successfully reduce framework cost (drop performance caused by framework implementation).

image

2reactions
ktutnikcommented, Jun 28, 2019

The latest commit of TypedConverter has more performance than Joi (more than twice faster than Joi)

image

  • Implement AST based logic
  • Added visitor hook to extends internal process of type conversion
  • Implement base validation function (this function should not decrease overall performance)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Performance (from 45 fps to 64 fps) tweak for Wolcen 1.0.11.0
After last patch my game performance suffered a noticeable fps hit in specific locations. I tested few settings and the outcome is a...
Read more >
Dramatically increase performance / FPS with any setup! DayZ ...
DayZ fps increase guide, FULL Release, Beta, 1.0 dayz standlone more fps, fix lag and stutter✔️ better fps, boost fps within DAYZLets try ......
Read more >
Batman Tweak - Utility to Tweak Performance (v 1.01)
In Nvidia control panel, enable v-sync and triple buffering (don't use in-game) if you want v-sync. Then, change 'max prerendered frames' to 4....
Read more >
Download Win7 Speed Tweaks 1.0
Win7 Speed Tweaks is a small collection of various registry tweaks that will improve the performance of your Windows 7 computer.
Read more >
Windows 10 Ultimate Gaming Tweak Guide - BoredGamer
I play a lot of games and haven't found a comprehensive guide on Tweaking Windows 10 for Gaming, Performance, System Tweaks, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found