pion / stun

A Go implementation of STUN
https://pion.ly/
MIT License
625 stars 94 forks source link

Message buffer usage optimization #19

Closed ernado closed 5 years ago

ernado commented 5 years ago

While retrospectively reviewing the stun library I've discovered some things that I've missed during refactoring iterations.

1) The grow method actual usage expects different implementation. 2) Text attributes like Nonce are doing implicit copy instead of referencing the original buffer.

This PR addresses both issues. I see no backward incompatible changes except probable misuse of text attributes, e.g. using decoded Nonce after corresponding m.Raw is invalidated and reused.

The 1 will optimize memory allocation and fix possible unexpectedly big m.Raw-s, the 2 speed-up the Nonce, Username and other text attributes decode time and memory consumption.

codecov[bot] commented 5 years ago

Codecov Report

Merging #19 into master will not change coverage. The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master    #19   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          19     19           
  Lines        1207   1209    +2     
=====================================
+ Hits         1207   1209    +2
Impacted Files Coverage Δ
message.go 100% <100%> (ø) :arrow_up:
textattrs.go 100% <100%> (ø) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 8136435...1fa2bd2. Read the comment docs.