save-buffer commented on a change in pull request #12537:
URL: https://github.com/apache/arrow/pull/12537#discussion_r829549783



##########
File path: cpp/src/arrow/compute/exec/tpch_node.cc
##########
@@ -0,0 +1,3431 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "arrow/compute/exec/tpch_node.h"
+#include "arrow/util/future.h"
+#include "arrow/util/make_unique.h"
+#include "arrow/util/unreachable.h"
+
+#include <algorithm>
+#include <bitset>
+#include <cstring>
+#include <memory>
+#include <mutex>
+#include <queue>
+#include <random>
+#include <unordered_set>
+#include <vector>
+
+namespace arrow {
+using internal::checked_cast;
+
+namespace compute {
+const char* NameParts[] = {
+    "almond",    "antique",    "aquamarine", "azure",     "beige",    "bisque",
+    "black",     "blanched",   "blue",       "blush",     "brown",    
"burlywood",
+    "burnished", "chartreuse", "chiffon",    "chocolate", "coral",    
"cornflower",
+    "cornsilk",  "cream",      "cyan",       "dark",      "deep",     "dim",
+    "dodger",    "drab",       "firebrick",  "floral",    "forest",   
"frosted",
+    "gainsboro", "ghost",      "goldenrod",  "green",     "grey",     
"honeydew",
+    "hot",       "indian",     "ivory",      "khaki",     "lace",     
"lavender",
+    "lawn",      "lemon",      "light",      "lime",      "linen",    
"magenta",
+    "maroon",    "medium",     "metallic",   "midnight",  "mint",     "misty",
+    "moccasin",  "navajo",     "navy",       "olive",     "orange",   "orchid",
+    "pale",      "papaya",     "peach",      "peru",      "pink",     "plum",
+    "powder",    "puff",       "purple",     "red",       "rose",     "rosy",
+    "royal",     "saddle",     "salmon",     "sandy",     "seashell", "sienna",
+    "sky",       "slate",      "smoke",      "snow",      "spring",   "steel",
+    "tan",       "thistle",    "tomato",     "turquoise", "violet",   "wheat",
+    "white",     "yellow",
+};
+static constexpr size_t kNumNameParts = sizeof(NameParts) / 
sizeof(NameParts[0]);

Review comment:
       yes, and it matters a lot. these strings will be placed adjacent in 
memory (maybe spaced out for alignment) in the .rodata section of the binary. 
this means that if i load these strings for whatever reason (like generating 
comments!) it'll pull a bunch of them in within the same cache line, and while 
generating comments the whole block of strings will fit within cache. 
   
   what happens with `std::vector<std::string>`? before `main` is called, all 
of the constructors of static objects will be called. this means that we will 
allocate the vector on the heap. then, we'll do a million tiny allocations for 
these strings, and these strings will be copied from `.rodata` onto the heap. 
further, we have no idea where the allocator will put these strings, they could 
just be in random places in memory (i.e. terrible for cache). 
   
   so basically we end up with something that's worse in every way: double the 
memory gets used, cache performance is worse, startup time is longer




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to