git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: On Tabs and Spaces

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Oct 18, 2007, 03:13 UTC
Message-ID
<alpine.LFD.0.999.0710171955580.26902@woody.linux-foundation.org>
In-Reply-To
<20071018024553.GA5186@coredump.intra.peff.net>
On Wed, 17 Oct 2007, Jeff King wrote:
Show 9 quoted lines
> 
> You have made this claim several times, and I really don't understand
> it. If I have 8 spaces, then a diff line will have either " ", "+", or
> "-" followed by 8 spaces. If I use a hard tab, then the tab will end up
> only taking up 7 spaces because of the nature of tabs.
> 
> This might matter if I'm comparing non-diff code to diff code. But in a
> diff, _everything_ is indented by exactly one space, so it all lines up.
> Is there something I'm missing?
Yes. 
You're missing the fact that some people have problems with editors.

So they add a line, and they add *that* line with the wrong kind of indentation. And it shows up among the other lines like this (here the whole patch is indented):

	diff --git a/kernel/sched.c b/kernel/sched.c
	index 92721d1..1ecb164 100644
	--- a/kernel/sched.c
	+++ b/kernel/sched.c
	@@ -127,6 +127,7 @@ static inline u32 sg_div_cpu_power(const struct sched_group *sg, u32 load)
	 static inline void sg_inc_cpu_power(struct sched_group *sg, u32 val)
	 {
	 	sg->__cpu_power += val;
	+        wrong indentation here.
	 	sg->reciprocal_cpu_power = reciprocal_value(sg->__cpu_power);
	 }
	 #endif
and so you see the fact that somebody messed up in the patch itself.

It actually more often goes the other way: somebody may have messed up earlier, but did so *consistently* so it wasn't obvious when looking at the patch. And then somebody fixes one line, and now that one fixed line is indented correctly but differently.

When it gets *too* bad, we just reindent the whole file, but more commonly when I notice it in a diff, I just edit that particular region or even just the diff itself in-place.

Generally, it seldom comes to even that. Doing a
	git grep '        ' -- '*.c'

(that's now eight spaces) returns quite a lot of lines, and it's generally not worth worrying about (not all of them are indentation - people do use spaces for lining things up etc - but a lot of it really is just indents done against the coding style).

> I was about to tell you that you're full of it, but there really is a
> slowdown:
>  [ ... ]
> It's actually about 16%.

I didn't even time it, and I called it at 20% without even counting any tabs. Why? Because it's inevitable!

It so happens that "grep" has a lot of really clever heuristics, so that it is actually better at passing over characters that it knows cannot start the pattern you are searching for, so timing "grep" is actually quite complex in the general case. So I bet that if you had grepped for something that started with a space, you'd probably have found a bigger slowdown.

But ignore all that complexity, and it really boils down to a really simple principle: bigger data sets are more expensive, and "linear slowdown" is actually almost the best possible case. Quite often, a bigger data set causes *worse* than a linear slowdown.

It's very seldom the case that you grow some problem space and performance stays the same.

> Gah, I can't believe I've not only been sucked into a tab vs spaces
> discussion, but now I've actually wasted time doing a performance
> comparison on it.

Well, performance analysis isn't exactly a "waste". That "git grep" was something we spent some time trying to go fast (for example, doing the whole external grep tool thing because that thing is usually optimized to h*ll and back - so the execve() overhead is more than worth it).

And it's a real workload. Maybe others don't use "git grep" quite as much as I do, but I do it *all* the time. Some other people probably use ctags or something, I personally prefer just a fast git grep.

But the *exact* same issues will show up for "simple" things like "git bisect". One of the biggest costs of git bisect is actually checking out the source tree. If the source tree is on the order of 20% larger, what does that mean?

So it doesn't matter if you have a terabyte disk. Source code size *still* matters.

And 20% (or 16%) is more than a lot of other optimizations can help you save!

> As an aside, that commit was enough to trigger a "git-gc --auto", which
> was my first experience with it. It's actually kind of annoying
> (especially since I was about to repack -a -d).

Yeah, I don't think it's wonderful, but it might even be a good thing as a "hey, at least you are aware of the notion of GC now" kind of introduction to people (who then hopefully realize that they don't actually want automatic GC, but rather do it once a week or something).

		Linus
Previous: Linus TorvaldsNext: Jeff King
Message 71 of 100 in “On Tabs and Spaces”
  1. Michael WittenOct 16, 2007
  2. Shawn O. PearceOct 16, 2007
  3. Michael WittenOct 16, 2007
  4. Andreas EricssonOct 16, 2007
  5. Sam RavnborgOct 16, 2007
  6. Petr BaudisOct 16, 2007
  7. DavidOct 17, 2007
  8. Andy ParkinsOct 17, 2007
  9. Adam PiatyszekOct 16, 2007
  10. Lars HjemliOct 16, 2007
  11. Adam PiatyszekOct 16, 2007
  12. Jeffrey C. OllieOct 16, 2007
  13. Michael WittenOct 16, 2007
  14. Jari AaltoOct 16, 2007
  15. Linus TorvaldsOct 16, 2007
  16. Mike HommeyOct 16, 2007
  17. Linus TorvaldsOct 16, 2007
  18. Linus TorvaldsOct 16, 2007
  19. Matthieu MoyOct 16, 2007
  20. Tom TobinOct 16, 2007
  21. Linus TorvaldsOct 16, 2007
  22. Christer WeinigelOct 16, 2007
  23. Linus TorvaldsOct 17, 2007
  24. Michael WittenOct 17, 2007
  25. Linus TorvaldsOct 17, 2007
  26. Luke LuOct 17, 2007
  27. Michael WittenOct 17, 2007
  28. Luke LuOct 17, 2007
  29. Nikolai WeibullOct 17, 2007
  30. Michael WittenOct 17, 2007
  31. Jari AaltoOct 17, 2007
  32. Andreas EricssonOct 17, 2007
  33. Jari AaltoOct 17, 2007
  34. Dmitry TorokhovOct 18, 2007
  35. Jari AaltoOct 18, 2007
  36. Petr BaudisOct 18, 2007
  37. Nikolai WeibullOct 18, 2007
  38. Miles BaderOct 22, 2007
  39. David KågedalOct 18, 2007
  40. Mike HommeyOct 18, 2007
  41. Jari AaltoOct 18, 2007
  42. Linus TorvaldsOct 17, 2007
  43. Johannes SchindelinOct 17, 2007
  44. Tom TobinOct 17, 2007
  45. Linus TorvaldsOct 17, 2007
  46. Tom TobinOct 17, 2007
  47. Linus TorvaldsOct 17, 2007
  48. Nicolas PitreOct 17, 2007
  49. Josh EnglandOct 17, 2007
  50. Linus TorvaldsOct 17, 2007
  51. Christer WeinigelOct 17, 2007
  52. Linus TorvaldsOct 17, 2007
  53. David KastrupOct 18, 2007
  54. Johannes SchindelinOct 17, 2007
  55. Christer WeinigelOct 17, 2007
  56. Johannes SchindelinOct 17, 2007
  57. Christer WeinigelOct 18, 2007
  58. Andreas EricssonOct 18, 2007
  59. David KågedalOct 18, 2007
  60. Linus TorvaldsOct 17, 2007
  61. David KastrupOct 17, 2007
  62. Johannes SchindelinOct 17, 2007
  63. Jan WielemakerOct 17, 2007
  64. Jeff KingOct 18, 2007
  65. Linus TorvaldsOct 18, 2007
  66. Jeff KingOct 18, 2007
  67. david@lang.hmOct 18, 2007
  68. Jeff KingOct 18, 2007
  69. Linus TorvaldsOct 18, 2007
  70. Linus TorvaldsOct 18, 2007
  71. Linus TorvaldsOct 18, 2007
  72. Jeff KingOct 18, 2007
  73. Add a message explaining that automatic GC is about to startkoreth@midwinter.com, Oct 18, 2007
  74. Steven GrimmOct 18, 2007
  75. Jeff KingOct 18, 2007
  76. Shawn O. PearceOct 18, 2007
  77. Brian GernhardtOct 18, 2007
  78. Steven GrimmOct 18, 2007
  79. Jeff KingOct 18, 2007
  80. Shawn O. PearceOct 19, 2007
  81. git-gc: improve wording of --auto notificationJeff King, Oct 19, 2007
  82. Shawn O. PearceOct 19, 2007
  83. Jeff KingOct 19, 2007
  84. Nicolas PitreOct 18, 2007
  85. Nicolas PitreOct 18, 2007
  86. Jeff KingOct 18, 2007
  87. Jeff KingOct 18, 2007
  88. David KastrupOct 17, 2007
  89. Nicolas PitreOct 17, 2007
  90. David KastrupOct 17, 2007
  91. SeanOct 17, 2007
  92. David KastrupOct 17, 2007
  93. Sam RavnborgOct 16, 2007
  94. Paul WankadiaOct 18, 2007
  95. Linus TorvaldsOct 18, 2007
  96. Dmitry PotapovOct 18, 2007
  97. Andreas EricssonOct 16, 2007
  98. Jan-Benedict GlawOct 16, 2007
  99. Andreas EricssonOct 16, 2007
  100. Robin RosenbergOct 20, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.