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

perf(crypto): avoid copying twice when returning a polynomial #371

Merged
merged 1 commit into from
Apr 4, 2024

Conversation

chokobole
Copy link
Contributor

@chokobole chokobole commented Apr 2, 2024

Description

The need for this optimization stems from the internal copying that occurs during multiplication and division between the polynomials. With Poly& * operand, copying occurs twice, so we use Poly * operand instead so that copying occurs just once.

Poly Func() {
  Poly& poly;
  Poly operand;
  return poly *= operand; // copying twice
}
Poly Func() {
  Poly& poly;
  Poly operand;
  return poly * operand; // copying once
}

@ashjeong ashjeong changed the title perf(crypto): avoid copying twice when returning polynomial perf(crypto): avoid copying twice when returning a polynomial Apr 3, 2024
Copy link
Contributor

@dongchangYoo dongchangYoo left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@Insun35 Insun35 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@TomTaehoonKim TomTaehoonKim left a comment

Choose a reason for hiding this comment

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

LGTM

The need for this optimization stems from the internal copying that occurs
during multiplication and division between the polynomials.
With `Poly& * operand`, copying occurs twice,
so we use `Poly * operand` instead so that copying occurs just once.

```c++
Poly Func() {
  Poly& poly;
  Poly operand;
  return poly *= operand; // copying twice
}
```

```c++
Poly Func() {
  Poly& poly;
  Poly operand;
  return poly * operand; // copying once
}
```
@chokobole chokobole force-pushed the perf/avoid-copying-twice-when-returning-poly branch from 88aa774 to f632757 Compare April 3, 2024 09:02
Copy link
Contributor

@ashjeong ashjeong left a comment

Choose a reason for hiding this comment

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

LGTM

@chokobole chokobole merged commit c3c6276 into main Apr 4, 2024
3 checks passed
@chokobole chokobole deleted the perf/avoid-copying-twice-when-returning-poly branch April 4, 2024 06:25
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.

None yet

5 participants