Open asl opened 2 months ago
I have no problems with switching out endl
, considering that this seem to be the recommended way: https://clang.llvm.org/extra/clang-tidy/checks/performance/avoid-endl.html
The only question is whether we can guarantee that we do end up flushing correctly?
I'm seeing possible ways of fixing this:
- Make
IndentCtl::endl
use\n
instead ofendl
- Switch Util::JSon not to use
endl
(though we'd need to expose current indent level then)Opinions? Tagging @ChrisDodd @grg @fruffy @vlstill
Since endl
is supposed to flush (by analogy with std::endl
, making it not flush would be problematic. Perhaps add IndentCtl::nl
to output a newline without flushing?
One of my thought for IndentCtl was to redo it by makeing it a streambuf and intercepting the overflow and inserting indentation there. That way it could do it automatically (and transparently) based on what was output, and could also wrap long lines properly. But that is a much bigger challenge
Since
endl
is supposed to flush (by analogy withstd::endl
, making it not flush would be problematic. Perhaps addIndentCtl::nl
to output a newline without flushing?
Glad you suggested this :) As this is exactly my existing solution downstream.
One of my thought for IndentCtl was to redo it by makeing it a streambuf and intercepting the overflow and inserting indentation there. That way it could do it automatically (and transparently) based on what was output, and could also wrap long lines properly. But that is a much bigger challenge
This does not seem it would worth the complexity, right.
And it turned out to be a bit tricky. The reason is that GC does not execute destructors for objects. As a result, the streams are never closed. And therefore what left in buffers is left there w/o explicit flush...
We are having the following code in
lib/indent.h
:So, doing
out << IndentCtl::endl
essentially flushes the output stream. This is more or less fine forcout / cerr
, howeverIndentCtl
is used inUtils::Json
. As a result, serialization of json objects become terrible expensive due to constant flushes of output file stream, e.g.:I'm seeing possible ways of fixing this:
IndentCtl::endl
use\n
instead ofendl
endl
(though we'd need to expose current indent level then)Opinions? Tagging @ChrisDodd @grg @fruffy @vlstill