Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

performance optimization #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

springfieldking
Copy link

No description provided.

@@ -113,10 +104,10 @@ FEC::Input(fecPacket &pkt) {
int numDataShard = 0;
int first = 0;
size_t maxlen = 0;

std::vector<row_type> shardVec(totalShards);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

避免重复申请内存,对移动端更友好

@@ -33,13 +30,11 @@ FEC::New(int rxlimit, int dataShards, int parityShards) {
}

fecPacket
FEC::Decode(byte *data, size_t sz) {
FEC::Decode(byte *data, size_t sz, uint32_t ts) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fec更贴近协议栈, 通过业务传入时间更合理,避免了协议栈内部调用时间函数,效率更高

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以增加一个函数,而不仅是替换,这样可以保持兼容性

for (int n=0;n<in->size();n++) {
(*out)[n] = mulTable[c][(*in)[n]];
}
void galMulSlice(byte c, byte* in, byte* out, int size) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

矩阵计算相关 删除了vector和sharedptr的用法, 改为数组操作,效率提升十分明显,仅修改这一处,压测(编译-O2)的耗时就能减少一半

// Search recursively on the child node by passing in the invalid indices
// with the first index popped off the front. Also the parent index to
// pass down is the first index plus one.
std::vector<int> v(invalidIndices.begin() + 1, invalidIndices.end());
return node->getInvertedMatrix(v, firstIndex + 1);
// no copy std::vector<int> v(invalidIndices.begin() + 1, invalidIndices.end());
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

避免临时vector申请内存和拷贝。

// SwapRows Exchanges two rows in the matrix.
int SwapRows(int r1, int r2);
// IdentityMatrix returns an identity matrix of the given empty.
class IdentityMatrix : public Matrix {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

matrix模块做了较大的修改,矩阵模块拆分成类Matrix,单位矩阵和范德蒙矩阵。后两者从Matrix继承并且初始化。矩阵的操作拆分独立的函数,而非成员函数。矩阵的创建通过sharedptr创建,避免之前struct matrix结构复制拷贝。

@@ -63,24 +64,31 @@ ReedSolomon::Encode(std::vector<row_type> &shards) {
checkShards(shards, false);

// Get the slice of output buffers.
std::vector<row_type> output(shards.begin() + m_dataShards, shards.end());
static thread_local std::vector<byte*> output(shards.size() - m_dataShards);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static thread_local避免重复申请内存,对移动端更友好

#include <iostream>
#include <stdexcept>
#include "fec.h"
#include "sess.h"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个依赖有点奇怪,fec依赖sess,只是为了用其时间函数。

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

通过sess把时间传递到fec协议栈内更合理。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants