Does using large libraries inherently make slower code?

前端 未结 17 1553
情深已故
情深已故 2021-02-06 20:40

I have a psychological tic which makes me reluctant to use large libraries (like GLib or Boost) in lower-level languages like C and C++. In my mind, I think:

17条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-06 21:30

    Even if I only use one or two features of a large library, by linking to that library am I going to incur runtime performance overheads?

    In general, no.

    If the library in question doesn't have a lot of position-independent code, then there will be a start-up cost while the dynamic linker performs relocations on the library when it's requested. Usually, that's part of the program's start-up. There is no run-time performance effect beyond that.

    Linkers are also good at removing "dead code" from statically-linked libraries at build time, so any static libraries you use will have minimal size overhead. Performance doesn't even enter into it.

    Frankly, you're worrying about the wrong things.

提交回复
热议问题