23 Commits
Author SHA1 Message Date
xtaci 2693fa8e71 perf: reduce heap allocations and fix memory leaks across multiple components
Optimizations:
- ringbuffer: optimize Len(), IsEmpty(), Discard(), Clear() methods with
  branchless arithmetic and simplified logic
- fec: fix memory leak in shardHeap.Pop() by setting element to nil before
  truncating slice, preventing GC from holding stale references
- timedsched: fix memory leak in timedFuncHeap.Pop() with same nil-before-truncate
  pattern; optimize prepend() using slice swap instead of append
- autotune: add sortCache field to Autotuner to reuse slice allocation in
  FindPeriod(), avoiding repeated allocations during period detection
- snmp: replace fmt.Sprint with strconv.FormatUint for better performance
  in Copy() and Reset() methods
- entropy: remove defer overhead in rngAES.Read() and rngChacha8.Read()
  hot paths for reduced function call cost
- bufferpool: pre-allocate ErrBufferPoolSizeExceeded error; reset slice
  length on Put() to allow proper reuse
- sess: remove defer overhead in 6 setter methods (SetWriteDelay,
  SetWindowSize, SetStreamMode, SetACKNoDelay, SetDUP, SetNoDelay)

These changes reduce memory allocations, fix potential memory leaks in
heap-based data structures, and eliminate defer overhead in frequently
called methods.
2026-01-29 12:22:33 +08:00
xtaci e8b70f75f1 fix comment 2025-06-11 11:20:07 +08:00
xtaci 4a2c9f344a include the MIT license 2025-06-08 19:55:07 +08:00
xtaci 75045ccde3 make clear keep the capacity 2025-06-08 19:49:24 +08:00
xtaci 02fb643df7 remove a wrong comment 2025-06-08 19:27:19 +08:00
xtaci 3328f8333f use explict return in ringbuffer iterator 2025-06-08 12:18:10 +08:00
xtaci fee9135fb4 fix iteration in ring 2025-06-08 12:15:44 +08:00
IceFale 22f24b0c92 Adopt the usage of RingBuffer[T] for snd_buf. (#291) 2025-06-08 11:41:32 +08:00
xtaci 9a9404e150 adjust RINGBUFFER_EXP to 1024 2025-06-08 11:25:54 +08:00
xtaci 87c6a0f86d use pointer in ForEach 2025-06-06 19:39:56 +08:00
xtaci 74ec44c7e1 add foreach test in ringbuffer 2025-06-06 17:18:44 +08:00
xtaci 20b3456154 fix length in ringbuffer 2025-06-06 16:17:43 +08:00
xtaci 71e90c5ae9 MaxLen returns len(r.elements) - 1 2025-06-06 14:29:54 +08:00
xtaci f7100c9c66 make constants 2025-06-06 14:13:35 +08:00
xtaci fb0f44f470 fix edge 2025-06-06 13:50:55 +08:00
xtaci 68f0b23be9 fix a border 2025-06-06 13:31:50 +08:00
xtaci af0d8e120f Squashed commit of the following:
commit 6dd97ddbc2
Author: xtaci <imap@live.com>
Date:   Fri Jun 6 13:08:58 2025 +0800

    Squashed commit of the following:

    commit e833f42c68
    Author: xtaci <imap@live.com>
    Date:   Fri Jun 6 13:03:22 2025 +0800

        added more test

    commit 57242b8c05
    Author: xtaci <imap@live.com>
    Date:   Fri Jun 6 11:47:45 2025 +0800

        use ringed rcv_queue

    commit 56de076e83
    Author: xtaci <imap@live.com>
    Date:   Fri Jun 6 11:18:40 2025 +0800

        Squashed commit of the following:

        commit 745517fcc4
        Author: xtaci <imap@live.com>
        Date:   Fri Jun 6 11:13:27 2025 +0800

            fix grow

        commit 1b6d34570a
        Author: xtaci <imap@live.com>
        Date:   Fri Jun 6 10:48:07 2025 +0800

            Squashed commit of the following:

            commit 8f90af5057
            Author: xtaci <imap@live.com>
            Date:   Fri Jun 6 10:46:52 2025 +0800

                add ForEach in ringbuffer

            commit 82250c1f06
            Author: xtaci <imap@live.com>
            Date:   Fri Jun 6 10:29:23 2025 +0800

                add test for grow()

            commit 174824b596
            Author: xtaci <imap@live.com>
            Date:   Fri Jun 6 10:08:05 2025 +0800

                remove fmt.Print

            commit 6534dfe542
            Author: xtaci <imap@live.com>
            Date:   Fri Jun 6 10:06:18 2025 +0800

                rename to ringbuffer

            commit 2f44ba9a82
            Author: xtaci <imap@live.com>
            Date:   Fri Jun 6 10:03:14 2025 +0800

                add comments

            commit 3f49975468
            Author: xtaci <imap@live.com>
            Date:   Fri Jun 6 10:02:14 2025 +0800

                save

            commit c505f434cc
            Author: xtaci <daniel820313@gmail.com>
            Date:   Thu Jun 5 17:47:17 2025 +0800

                add ring

        commit 3b4daea2cd
        Author: FULI <daniel820313@gmail.com>
        Date:   Fri Jun 6 10:30:51 2025 +0800

            RingBuffer (#290)

            * add ring

            * save

            * add comments

            * rename to ringbuffer

            * remove fmt.Print

            * add test for grow()

        commit e0169fb60e
        Author: xtaci <imap@live.com>
        Date:   Sun May 25 00:09:13 2025 +0800

            make fec.go more clear

        commit 97d2673e8a
        Author: xtaci <imap@live.com>
        Date:   Wed May 21 13:55:08 2025 +0800

            add comments to fec.go

        commit 5ef7e8042f
        Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
        Date:   Tue May 20 10:38:46 2025 +0800

            Bump golang.org/x/net from 0.36.0 to 0.38.0 (#287)

            Bumps [golang.org/x/net](https://github.com/golang/net) from 0.36.0 to 0.38.0.
            - [Commits](https://github.com/golang/net/compare/v0.36.0...v0.38.0)

            ---
            updated-dependencies:
            - dependency-name: golang.org/x/net
              dependency-version: 0.38.0
              dependency-type: direct:production
            ...

            Signed-off-by: dependabot[bot] <support@github.com>
            Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

        commit 11ae2d1c3e
        Author: xtaci <imap@live.com>
        Date:   Tue Apr 15 10:40:08 2025 +0800

            update go.mod

        commit 53b48e42c2
        Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
        Date:   Tue Apr 15 10:38:02 2025 +0800

            Bump golang.org/x/net from 0.23.0 to 0.36.0 (#286)

            Bumps [golang.org/x/net](https://github.com/golang/net) from 0.23.0 to 0.36.0.
            - [Commits](https://github.com/golang/net/compare/v0.23.0...v0.36.0)

            ---
            updated-dependencies:
            - dependency-name: golang.org/x/net
              dependency-version: 0.36.0
              dependency-type: direct:production
            ...

            Signed-off-by: dependabot[bot] <support@github.com>
            Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

        commit f327c26f53
        Author: Roman Gurov <44749519+rgurov@users.noreply.github.com>
        Date:   Fri Apr 11 05:11:14 2025 +0300

            fix: typo in README.md (#284)

        commit c5078bd33b
        Author: Roman Gurov <44749519+rgurov@users.noreply.github.com>
        Date:   Wed Apr 9 10:44:14 2025 +0300

            fix: make timeout error implement net.Error (#283)

        commit 3c579515d6
        Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
        Date:   Tue Feb 18 14:33:01 2025 +0800

            Bump golang.org/x/crypto from 0.21.0 to 0.31.0 (#281)

            Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.21.0 to 0.31.0.
            - [Commits](https://github.com/golang/crypto/compare/v0.21.0...v0.31.0)

            ---
            updated-dependencies:
            - dependency-name: golang.org/x/crypto
              dependency-type: direct:production
            ...

            Signed-off-by: dependabot[bot] <support@github.com>
            Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

        commit 5c80bedd4b
        Author: xiabin <snyh@snyh.org>
        Date:   Fri Dec 27 13:08:22 2024 +0800

            fix: reading low-level net.PacketConn when UDPSession is closed (#280)

    commit 8f90af5057
    Author: xtaci <imap@live.com>
    Date:   Fri Jun 6 10:46:52 2025 +0800

        add ForEach in ringbuffer

    commit 82250c1f06
    Author: xtaci <imap@live.com>
    Date:   Fri Jun 6 10:29:23 2025 +0800

        add test for grow()

    commit 174824b596
    Author: xtaci <imap@live.com>
    Date:   Fri Jun 6 10:08:05 2025 +0800

        remove fmt.Print

    commit 6534dfe542
    Author: xtaci <imap@live.com>
    Date:   Fri Jun 6 10:06:18 2025 +0800

        rename to ringbuffer

    commit 2f44ba9a82
    Author: xtaci <imap@live.com>
    Date:   Fri Jun 6 10:03:14 2025 +0800

        add comments

    commit 3f49975468
    Author: xtaci <imap@live.com>
    Date:   Fri Jun 6 10:02:14 2025 +0800

        save

    commit c505f434cc
    Author: xtaci <daniel820313@gmail.com>
    Date:   Thu Jun 5 17:47:17 2025 +0800

        add ring

commit 745517fcc4
Author: xtaci <imap@live.com>
Date:   Fri Jun 6 11:13:27 2025 +0800

    fix grow

commit 1b6d34570a
Author: xtaci <imap@live.com>
Date:   Fri Jun 6 10:48:07 2025 +0800

    Squashed commit of the following:

    commit 8f90af5057
    Author: xtaci <imap@live.com>
    Date:   Fri Jun 6 10:46:52 2025 +0800

        add ForEach in ringbuffer

    commit 82250c1f06
    Author: xtaci <imap@live.com>
    Date:   Fri Jun 6 10:29:23 2025 +0800

        add test for grow()

    commit 174824b596
    Author: xtaci <imap@live.com>
    Date:   Fri Jun 6 10:08:05 2025 +0800

        remove fmt.Print

    commit 6534dfe542
    Author: xtaci <imap@live.com>
    Date:   Fri Jun 6 10:06:18 2025 +0800

        rename to ringbuffer

    commit 2f44ba9a82
    Author: xtaci <imap@live.com>
    Date:   Fri Jun 6 10:03:14 2025 +0800

        add comments

    commit 3f49975468
    Author: xtaci <imap@live.com>
    Date:   Fri Jun 6 10:02:14 2025 +0800

        save

    commit c505f434cc
    Author: xtaci <daniel820313@gmail.com>
    Date:   Thu Jun 5 17:47:17 2025 +0800

        add ring

commit 3b4daea2cd
Author: FULI <daniel820313@gmail.com>
Date:   Fri Jun 6 10:30:51 2025 +0800

    RingBuffer (#290)

    * add ring

    * save

    * add comments

    * rename to ringbuffer

    * remove fmt.Print

    * add test for grow()

commit e0169fb60e
Author: xtaci <imap@live.com>
Date:   Sun May 25 00:09:13 2025 +0800

    make fec.go more clear

commit 97d2673e8a
Author: xtaci <imap@live.com>
Date:   Wed May 21 13:55:08 2025 +0800

    add comments to fec.go

commit 5ef7e8042f
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Tue May 20 10:38:46 2025 +0800

    Bump golang.org/x/net from 0.36.0 to 0.38.0 (#287)

    Bumps [golang.org/x/net](https://github.com/golang/net) from 0.36.0 to 0.38.0.
    - [Commits](https://github.com/golang/net/compare/v0.36.0...v0.38.0)

    ---
    updated-dependencies:
    - dependency-name: golang.org/x/net
      dependency-version: 0.38.0
      dependency-type: direct:production
    ...

    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

commit 11ae2d1c3e
Author: xtaci <imap@live.com>
Date:   Tue Apr 15 10:40:08 2025 +0800

    update go.mod

commit 53b48e42c2
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Tue Apr 15 10:38:02 2025 +0800

    Bump golang.org/x/net from 0.23.0 to 0.36.0 (#286)

    Bumps [golang.org/x/net](https://github.com/golang/net) from 0.23.0 to 0.36.0.
    - [Commits](https://github.com/golang/net/compare/v0.23.0...v0.36.0)

    ---
    updated-dependencies:
    - dependency-name: golang.org/x/net
      dependency-version: 0.36.0
      dependency-type: direct:production
    ...

    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

commit f327c26f53
Author: Roman Gurov <44749519+rgurov@users.noreply.github.com>
Date:   Fri Apr 11 05:11:14 2025 +0300

    fix: typo in README.md (#284)

commit c5078bd33b
Author: Roman Gurov <44749519+rgurov@users.noreply.github.com>
Date:   Wed Apr 9 10:44:14 2025 +0300

    fix: make timeout error implement net.Error (#283)

commit 3c579515d6
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Tue Feb 18 14:33:01 2025 +0800

    Bump golang.org/x/crypto from 0.21.0 to 0.31.0 (#281)

    Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.21.0 to 0.31.0.
    - [Commits](https://github.com/golang/crypto/compare/v0.21.0...v0.31.0)

    ---
    updated-dependencies:
    - dependency-name: golang.org/x/crypto
      dependency-type: direct:production
    ...

    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

commit 5c80bedd4b
Author: xiabin <snyh@snyh.org>
Date:   Fri Dec 27 13:08:22 2024 +0800

    fix: reading low-level net.PacketConn when UDPSession is closed (#280)
2025-06-06 13:09:30 +08:00
xtaci e833f42c68 added more test 2025-06-06 13:03:22 +08:00
xtaci 56de076e83 Squashed commit of the following:
commit 745517fcc4
Author: xtaci <imap@live.com>
Date:   Fri Jun 6 11:13:27 2025 +0800

    fix grow

commit 1b6d34570a
Author: xtaci <imap@live.com>
Date:   Fri Jun 6 10:48:07 2025 +0800

    Squashed commit of the following:

    commit 8f90af5057
    Author: xtaci <imap@live.com>
    Date:   Fri Jun 6 10:46:52 2025 +0800

        add ForEach in ringbuffer

    commit 82250c1f06
    Author: xtaci <imap@live.com>
    Date:   Fri Jun 6 10:29:23 2025 +0800

        add test for grow()

    commit 174824b596
    Author: xtaci <imap@live.com>
    Date:   Fri Jun 6 10:08:05 2025 +0800

        remove fmt.Print

    commit 6534dfe542
    Author: xtaci <imap@live.com>
    Date:   Fri Jun 6 10:06:18 2025 +0800

        rename to ringbuffer

    commit 2f44ba9a82
    Author: xtaci <imap@live.com>
    Date:   Fri Jun 6 10:03:14 2025 +0800

        add comments

    commit 3f49975468
    Author: xtaci <imap@live.com>
    Date:   Fri Jun 6 10:02:14 2025 +0800

        save

    commit c505f434cc
    Author: xtaci <daniel820313@gmail.com>
    Date:   Thu Jun 5 17:47:17 2025 +0800

        add ring

commit 3b4daea2cd
Author: FULI <daniel820313@gmail.com>
Date:   Fri Jun 6 10:30:51 2025 +0800

    RingBuffer (#290)

    * add ring

    * save

    * add comments

    * rename to ringbuffer

    * remove fmt.Print

    * add test for grow()

commit e0169fb60e
Author: xtaci <imap@live.com>
Date:   Sun May 25 00:09:13 2025 +0800

    make fec.go more clear

commit 97d2673e8a
Author: xtaci <imap@live.com>
Date:   Wed May 21 13:55:08 2025 +0800

    add comments to fec.go

commit 5ef7e8042f
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Tue May 20 10:38:46 2025 +0800

    Bump golang.org/x/net from 0.36.0 to 0.38.0 (#287)

    Bumps [golang.org/x/net](https://github.com/golang/net) from 0.36.0 to 0.38.0.
    - [Commits](https://github.com/golang/net/compare/v0.36.0...v0.38.0)

    ---
    updated-dependencies:
    - dependency-name: golang.org/x/net
      dependency-version: 0.38.0
      dependency-type: direct:production
    ...

    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

commit 11ae2d1c3e
Author: xtaci <imap@live.com>
Date:   Tue Apr 15 10:40:08 2025 +0800

    update go.mod

commit 53b48e42c2
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Tue Apr 15 10:38:02 2025 +0800

    Bump golang.org/x/net from 0.23.0 to 0.36.0 (#286)

    Bumps [golang.org/x/net](https://github.com/golang/net) from 0.23.0 to 0.36.0.
    - [Commits](https://github.com/golang/net/compare/v0.23.0...v0.36.0)

    ---
    updated-dependencies:
    - dependency-name: golang.org/x/net
      dependency-version: 0.36.0
      dependency-type: direct:production
    ...

    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

commit f327c26f53
Author: Roman Gurov <44749519+rgurov@users.noreply.github.com>
Date:   Fri Apr 11 05:11:14 2025 +0300

    fix: typo in README.md (#284)

commit c5078bd33b
Author: Roman Gurov <44749519+rgurov@users.noreply.github.com>
Date:   Wed Apr 9 10:44:14 2025 +0300

    fix: make timeout error implement net.Error (#283)

commit 3c579515d6
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Tue Feb 18 14:33:01 2025 +0800

    Bump golang.org/x/crypto from 0.21.0 to 0.31.0 (#281)

    Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.21.0 to 0.31.0.
    - [Commits](https://github.com/golang/crypto/compare/v0.21.0...v0.31.0)

    ---
    updated-dependencies:
    - dependency-name: golang.org/x/crypto
      dependency-type: direct:production
    ...

    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

commit 5c80bedd4b
Author: xiabin <snyh@snyh.org>
Date:   Fri Dec 27 13:08:22 2024 +0800

    fix: reading low-level net.PacketConn when UDPSession is closed (#280)
2025-06-06 11:18:40 +08:00
xtaci 8f90af5057 add ForEach in ringbuffer 2025-06-06 10:46:52 +08:00
xtaci 82250c1f06 add test for grow() 2025-06-06 10:29:23 +08:00
xtaci 174824b596 remove fmt.Print 2025-06-06 10:08:05 +08:00
xtaci 6534dfe542 rename to ringbuffer 2025-06-06 10:06:18 +08:00