8000 executable size is too large · Issue #9 · c42f/tinyformat · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

executable size is too large 8000 #9

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

Closed
rockeet opened this issue May 16, 2014 · 4 comments
Closed

executable size is too large #9

rockeet opened this issue May 16, 2014 · 4 comments

Comments

@rockeet
Copy link
rockeet commented May 16, 2014

header only is not an advantage for safe printf, A more efficient implementation should just use variadic template to compute a type-signature-array, and pass to an external_linkage_safe_printf function along with other parameters

@c42f
Copy link
Owner
c42f commented May 16, 2014

I think header-only can be an advantage if you value convenience over code size. If there's a way to get both then I'd certainly like to hear about it.

I'm not sure I quite understand what you mean by an external_linkage_safe_printf. One possibility that I've considered in the past is to compute an array of Formatter objects (one for each argument). Each formatter in the array would simply wrap a reference to an argument and know how to format it onto a std::ostream, thus capturing the required type information.

There's multiple advantages to this:

  • The formatter array could then be passed around to user-defined functions (somewhat like a typesafe version of the C va_list)
  • The printf() implementation could exist as a single non-template function, potentially solving some bloat issues (though a Formatter object instantiation would still be required per type T).
  • The array could be traversed in any order, allowing for posix printf() positional arguments.

Is this the kind of thing you had in mind?

Of course, there's also some downsides:

  • The implementation would be somewhat more complex
  • Formatting each argument would involve an extra indirection through a function pointer or vtable. I'm not sure if this is really something to worry about though.

@c42f
Copy link
Owner
c42f commented May 16, 2014

BTW, this is related to issue #7. tinyformat code size used to be a lot smaller (at least with g++), but it's gotten worse with recent versions.

@c42f
Copy link
Owner
c42f commented May 24, 2014

I've pushed some experimental changes to help address this in the formatter_list branch (C++11 support only for now). The version in git still has everything in the header, but breaking out the formatImpl() function and other functions used by it into a tinyformat.cpp leads to a really nice code footprint:

./bloat_test.sh -DUSE_TINYFORMAT -std=c++0x -O3 -DNDEBUG

real 0m18.861s
user 0m16.493s
sys 0m1.756s
100K bloat_test_tmp.out
76K bloat_test_tmp.out

That's getting quite respectably small - a factor of about 10x improvement over the current master in fact :-)

@c42f
Copy link
Owner
c42f commented Jun 15, 2014

I'd say this is well and truly fixed as of 38173bb. With gcc-4.8.2, I now get:

$ ./bloat_test.sh -DUSE_TINYFORMAT -O3 -DNDEBUG

real    0m33.347s
user    0m31.324s
sys     0m2.010s
120K _bloat_test_tmp_.out
96K _bloat_test_tmp_stripped.out

Notably, this is with the header-only version so there's need to compromise on convenience, at least with gcc 4.8. Note also that the same version weighs in at 80K stripped for an iostreams implementation of the same formatting, so there's very little overhead here.

@c42f c42f closed this as completed Jun 15, 2014
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

No branches or pull requests

2 participants
0