Skip to content

[performance]: *OpenChannel.isBorked() is innefficient #7263

@matheusd

Description

@matheusd

Environment

lnd version
lnd version 0.15.99-beta commit=tor/v1.1.0-41-gb8545de5c
(This is a development version I just happen to have compiled, I can test on another one if requested).

go version
go version go1.19.3 linux/amd64

platform
linux/amd64

Description

I have setup the following test env to profile payment performance with 3 nodes (Alice <> Bob <> Charlie) and started a continuous stream of payments from Charlie to Alice, while profiling (with --profile <port>) on Bob.

While the payments were made, I fetched a profile with curl http://127.0.0.1:<port>/debug/pprof/profile?seconds=60 and reviewed the results.

The top offenders for CPU load during payment that I can eyeball are:

  1. bbolt.Tx.Commit()
  2. lnwallet.DeriveCommitmentKeys()
  3. channeldb.OpenChannel.isBorked()

While the first two are necessary (as they directly involve the protocol for updating channel state), upon reviewing the code for the third one, it seems less efficient than it could be. Specifically, it recreates the entire channel structure just to check the status of one specific field.

While I believe it's not absolutely safe to rely on the c.channStatus to check on the status (because other parts of the app might be using a different *OpenChannel instance to refer to the same underlying channel), this function could at least be improved upon by either reading the offset to the chanStatus field directly or reading and discarding the fields up to chanStatus and then returning immediately, which would improve performance.

I'm opening this issue prior to submitting a PR so that the best approach to solving this can be discussed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementImprovements to existing features / behaviour

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions