6 ms·
If you use grep in OS X, and you use it a lot (even called through other programs/libraries) it pays in time to install GNU grep vs. the default OS X provided o
by jcbeard 10y ago
If you use grep in OS X, and you use it a lot (even called through other programs/libraries) it pays in time to install GNU grep vs. the default OS X provided one. It's several times faster. Ran into this when benchmarking grep + GNU Parallel on OS X vs. Linux in my thesis (raftlib modeling) work. Results on my small MacPro cluster didn't match those on Linux. The OS X runs were orders of magnitude slower despite almost identical hardware configurations. The culprit as it turned out was largely the implementation of grep. I compiled with the GNU version, re-ran and the rest of the mis-match was simply due to the lack of POSIX features like thread pinning, and NUMA control.
<stepping up to soap box/> So yeah...as usual, algorithm matters. Implementation matters, and well....knowledge of the architecture/data-movement matter. These days the architecture/data-movement knowledge matters almost as much or more than the algorithm. Picking an algorithmically faster implementation that moves data more (e.g., tree traversals usually have poor cache behavior, more bursts required, etc.) is often the case b/c programmers don't really understand how the computer works, but are great at coding O(n logn) algorithms. We shouldn't stop teaching algorithms, but data-movement/access likely needs to be emphasized along with the understanding of algorithms.
- amelius 10y agoThis makes me wonder: why would Apple implement its own version of grep, and not simply ship GNU's version?
- pdpi 10y agoBecause Apple avoids GPLv3 like the plague, basically. That's why the included bash is so old too, AFAIK
- colejohnson66 10y agoWhich in this case is ridiculous. There are valid reasons for businesses to avoid GPL, but if they use GNU grep, the only thing they have to open source is their copy of GNU grep. It's not like doing so will force them to make their kernel GPL
- detaro 10y agoI'd assume their policy is because of the Tivoization clauses, which (as far as I understand them) would become an issue if they lock the OS down more, or want to share the environment with e.g. iOS devices.
- CJefferson 10y agoApple is moving towards forbidding write access to system directories, for example: sudo mv /bin/echo /bin/e mv: rename echo to e: Operation not permitted I'm not sure if this is getting close to falling foul of the GPL v3 -- if I can't replace these files, is that a problem?
- pohl 10y agoRather than replacing it, why not write it under /usr/local and edit your PATH?
- CJefferson 10y agoOh, I certainly could (and do for bash), but I believe the GPL v3 requires that you can replace any copies of programs with your own, which possibly Apple might worry they fall foul of, which might be why they don't want GPL v3 software (I'm guessing).
- colejohnson66 10y agoIs there anything stopping you from booting into Linux to rename it, is there? Like how I can't delete files owned by SYSTEM on Windows, but can on Linux?
- koenigdavidmj 10y agoYou can even unset this within macOS; it just requires a reboot: 1. Hold Cmd-R as you reboot. That puts you in recovery mode. 2. Bring up a terminal. 3. Run 'csrutil disable' 4. Reboot back into regular mode
- mikekchar 10y agogrep was already there from BSD, so no reason to add something new. However, speaking as a guy who started out on Sun BSD machines, the very first thing we did when we got a new box was to replace all the BSD utilities with GNU ones. Virtually all of them are better.
- danieldk 10y agogrep was already there from BSD FYI: OS X's grep is FreeBSD's bsdgrep. However, FreeBSD's default grep is still an ancient version of GNU grep (bsdgrep is only available as bsdgrep.). Also, older versions of OS X used to have GNU grep [1]. So the more likely explanation is Apple's purge of GPL code from OS X. Since later grep versions use GPLv3, GNU grep was a dead end for them. Unfortunately, FreeBSD's bsdgrep has some very annoying bugs (that are also present in OS X). No one seems to care about them, even when a patch is provided [2]. [1] http://opensource.apple.com/release/mac-os-x-1075/ http://opensource.apple.com/release/mac-os-x-1075/ [2] https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=201650 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=201650
- emaste 10y agoThe patch in [2] was added a bit over a month ago as a comment in a bug report about the GNU grep in the base system, so I don't think it's a good example of no one caring about bsdgrep bugs. On occasion I search for bsdgrep bugs, and did not find the comment / patch in [2]. Thank you for pointing it out, I'll look at it when I can.
- danieldk 10y agoThe patch in [2] was added a bit over a month ago as a comment in a bug report about the GNU grep in the base system, so I don't think it's a good example of no one caring about bsdgrep bugs. I FreeBSD developer requested that I added a report to that bug [1]. After adding the patch to the report, I also reported this to the list [2]. I have also tried to contact the maintainer of bsdgrep with no luck. At some point you just give up ;). [1] https://lists.freebsd.org/pipermail/freebsd-questions/2016-June/272372.html https://lists.freebsd.org/pipermail/freebsd-questions/2016-J... [2] https://lists.freebsd.org/pipermail/freebsd-questions/2016-July/272602.html https://lists.freebsd.org/pipermail/freebsd-questions/2016-J...
- jcbeard 10y agoSee article (http://meta.ath0.com/2012/02/05/apples-great-gpl-purge/)from http://meta.ath0.com/2012/02/05/apples-great-gpl-purge/)from previous HN post: https://news.ycombinator.com/item?id=3559990 https://news.ycombinator.com/item?id=3559990 Also, GNU's bulletin on Apple Boycott: https://www.gnu.org/bulletins/bull18.html#SEC13 https://www.gnu.org/bulletins/bull18.html#SEC13 And also this article which explains why apple is BSD mostly: https://scalibq.wordpress.com/2012/08/02/apples-os-x-is-not-linux/ https://scalibq.wordpress.com/2012/08/02/apples-os-x-is-not-...
- ccallebs 10y agoYour first link is redirecting to what I assume is a paid blog post. It's advertising and providing extensive backlinks for a computer desk.
- TAForObvReasons 10y agohttp://meta.ath0.com/2012/02/05/apples-great-gpl-purge/ http://meta.ath0.com/2012/02/05/apples-great-gpl-purge/ is the correct link, parent needs to put a space before the close paren raw text: http://hastebin.com/raw/zohoxaxuyi http://hastebin.com/raw/zohoxaxuyi
- jcbeard 10y agoAwesome, thanks for posting/fixing!
- loeg 10y agoThey ship an old version of BSD grep, presumably. Not their own implementation.
- jlarocco 10y agoApple uses BSD grep for basically the same reason FreeBSD uses BSD grep: GNU grep is GPL, and new versions are GPL v3.
- beachstartup 10y agoi've seen this getting worse with your typical developer in the age of "push the button to get another virtual machine and someone else will pay the bill."
- jasonpeacock 10y agoIf you use grep a lot, you should be using 'ag' (Silver Searcher): http://geoff.greer.fm/ag/ http://geoff.greer.fm/ag/
- happyslobro 10y agoOr ack (http://beyondgrep.com http://beyondgrep.com)
- kazinator 10y agoIf you use grep a lot over a code base, you should index it with "mkid" and use "lid" (gnu id-utils). Quasi-instant results.
- mastre_ 10y agoAbsolutely, more or less grep -> ack -> ag. Be warned tho, sometimes ag (and IIRC ack as well, but haven't used it in a while since switching to ag) won't find some results due to its default filtering rules even tho certain results should be included. For critical things, I end up double-checking results w/ grep -r which always finds everything, no questions asked.
- archagon 10y agoMy knowledge of architecture/data-movement is woefully inadequate. Where could someone go to brush up on this stuff?