node-postgres icon indicating copy to clipboard operation
node-postgres copied to clipboard

Do not parse command complete info unless accessed

Open brianc opened this issue 5 months ago • 2 comments

This is probably a bit of a micro-optimization, but in my own codebases the number of times I access any of these properties is nearly zero. So, not parsing the command complete message unless there's a reason to do so (user wants to know about the command complete info) seems reasonable.

brianc avatar Jul 16 '25 20:07 brianc

Slight change in behavior of the props of the result with this as those fields won't appear in any default serialization for things like logging:

class Props {
    constructor() {
        this.foo = 123;
    }
}

class Getter {
    get foo() {
        return 123;
    }
}

function debug(obj) {
    console.log('%j', {
        keys: Object.keys(obj),
        obj,
    });
}

const p = new Props();
debug(p);
const g = new Getter();
debug(g);
$ node test.js 
{"keys":["foo"],"obj":{"foo":123}}
{"keys":[],"obj":{}}

I doubt it matters in most apps in practice but may be good to call it out in the changelog.

sehrope avatar Jul 16 '25 21:07 sehrope

I doubt it matters in most apps in practice but may be good to call it out in the changelog.

hmm honestly it might not be worth changing if its gonna secretly break something esoteric on some deployed system. I didn't really notice much perf gain at all between the two implementations.

Thanks for your thoughts!! ❤️

brianc avatar Jul 16 '25 21:07 brianc