GithubHelp home page GithubHelp logo

Performance code review about oatpp HOT 6 CLOSED

oatpp avatar oatpp commented on May 19, 2024 22
Performance code review

from oatpp.

Comments (6)

Joshua-Ashton avatar Joshua-Ashton commented on May 19, 2024

But new does not return nullptr, it throws an exception.

This is "standard" correct, but not real world correct -- not everyone uses C++ exceptions (at the compiler level), therefore it could be nullptr. It's better to be safe than sorry.

from oatpp.

lganzzzo avatar lganzzzo commented on May 19, 2024

@FooBarWidget
Thank you so much for your code review, and your time!
It is very valuable input!

More documentation is really an issue and I am working on it right now.

Here is a brief answer and I will get back to you with the full answer a bit later:

What I do in Passenger is using smart pointers that do not use atomic counters.

I used to have custom smart-pointers in oat++ before but gave-up this idea in advantage for compatibility. So end-user could easier work with the framework.
Also performance impact was really very very small

I do not understand what ChunkedBuffer is supposed to be and how that's different from FifoBuffer

  • ChunkedBuffer is basically a chain of chunks. It provides possibility to grow buffer without copying the memory. Also chunks are pool allocated in order to reduce memory fragmentation.
  • FifoBuffer is for the future feature and not used currently.

On the conceptual level, I have no idea how the coroutine stuff works and is supposed to be used. I have also no idea what concurrency model you are using. Is it one-client-per-thread?

Currently there are two concurrency models implemented:

Coroutines and Async:
Are used in the async model together with non-blocking IO (non-blocking sockets).
Coroutines are served by oatpp::async::Processor.

These are stateless coroutines. On each iteration coroutine returns Action which is basically an action of what to do next. Action provides possibility for additional prioritization like put to "waiting queue" coroutine which waits for IO.

You may treat this approach like app-level implementation of epoll/kqueue. But this gives additional space for experiments and it makes end-user API a bit easier.

Did you manage to run some performance tests on your machine?

Thank you for the code-review once again!

from oatpp.

FooBarWidget avatar FooBarWidget commented on May 19, 2024

I added some edits. In particular, I added feedback about zero-copy.

Also performance impact was really very very small

In my experience with Passenger, such impact was indeed small on its own. But I optimized Passenger by solving a thousand paper cuts — optimizing 1% here, 0.5% there, 1.2% there, etc. They all added up.

from oatpp.

jcelerier avatar jcelerier commented on May 19, 2024

This is "standard" correct, but not real world correct -- not everyone uses C++ exceptions (at the compiler level), therefore it could be nullptr

I just tried with both GCC and clang : adding -fno-exceptions still makes new throw an exception so I guess the number of cases where new would return nullptr in real-world code is very very close from zero.

#include <cstdio>

int main()
{
  constexpr auto max = 100000000000;
  auto blob = new char[max];

  // the following added to ensure that the compiler does not 
  // optimize the allocation if it's not used
  auto f = fopen("/dev/null", "w");
  fwrite(blob, 1, max, f);
}

->

$ g++ -O3 foo.cpp -fno-exceptions 
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc

the generated assembly does not even change : https://gcc.godbolt.org/z/YCrwAX - looking how it's done in libc++ you would have to recompile it with an additional define for instance, and how many people are actually able to recompile their stdlib ?

from oatpp.

Joshua-Ashton avatar Joshua-Ashton commented on May 19, 2024

I was mainly referring to MSVC (not sure if this is the same behaviour as GCC now, it never used to be) and people who may override new with their own memory stuff in future.

from oatpp.

FooBarWidget avatar FooBarWidget commented on May 19, 2024

My point w.r.t. operator new and exceptions is that the calling code only checks for nullptr, but does not attempt to catch an exception.

from oatpp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.