Chapter 165: Forget It

My IQ Grows Every Year by Quiet Art (介安艺)

The background noise on the other end of the line was utter chaos.

Someone was hollering at the attendant to put another ten yuan on Section C, Machine 3. Someone else was pounding the desk and swearing, "Diu lei[1], you flashed me!" Under it all came a string of coughs and the click of lighters as people lit cigarettes.

Chen Zhuo held the landline receiver a little farther from his ear.

"Hang on."

Chu Ge shouted it from the other end. Chair legs scraped, and then the noise dropped a little, as if he had moved to a quieter corner.

"Okay, go ahead. I've found a pen."

Chu Ge had a lollipop between his teeth. He had the receiver clamped between his shoulder and his ear with his left hand, and with his right he fished a ballpoint pen out of a tangle of keyboard cables.

There was no paper on the desk. He looked around, pulled over the empty Master Kong braised beef instant noodle cup beside him, tore off its cardboard lid, which had a few drops of red chili oil on it, and turned it over.

The back of the lid was a little damp, but he could still write on it.

Chen Zhuo stood by the living-room window looking at the thin layer of frost on the glass. He reached out and drew a line through it.

"How is the database over in the capital built?" Chen Zhuo asked.

"Relational. Classic tree structure."

Chu Ge bit down hard on the lollipop a couple of times.

"They want to build a social network on six degrees of separation. The underlying logic is simple. I'm A, I know B, so the database stores one edge. Querying my friends is fast. Querying my friends' friends just about works."

Chu Ge's voice had the dry rasp of someone who had been up all night.

"But once you go three or four degrees down and you have more than two hundred concurrent users, the database has to run nested join after nested join. A table with a few hundred thousand users cross-multiplies into tens of millions of redundant rows in an instant."

"The guy in the capital said they just ran a stress test. Two hundred dummy accounts opened 'People You May Know' at the same time. The server fans spun up like a helicopter, the CPU went straight to a hundred percent, and three seconds later the database deadlocked."

Chu Ge sighed.

"Now it's a dead knot. If you want speed, you have to precompute every relationship and put it in a cache, but that takes huge amounts of memory and they can't afford that many servers. If you don't precompute and query live, the database falls over the moment a handful of people hit it at once."

Chen Zhuo heard him out and didn't answer right away.

He walked over and sat down on the sofa, took a peanut in its shell from the fruit plate, and gently cracked it open.

"Are you computer science people a bit stubborn?"

Chen Zhuo rubbed the skin off the peanut, sounding a little amused.

"Meaning what?"

Chu Ge was thrown.

"This is a pure graph theory problem. Why are you trying to solve it the way a cop checks the household register?"

Chen Zhuo popped the peanut into his mouth.

"Drop your nested queries. Treat every user as a point in a high-dimensional space, and every relationship between users as a line."

Chu Ge said nothing. His pen hovered over the noodle lid.

"Set up an adjacency matrix."

Chen Zhuo's voice was calm and even, as if he were walking someone through a freshman calculus homework problem in a university study room.

"Say you have a hundred thousand users. That's a hundred-thousand-by-hundred-thousand matrix A. If user i and user j are friends, the entry at (i, j) is 1. Otherwise it's 0."

"Wait."

Chu Ge cut in.

"A hundred thousand by a hundred thousand is ten billion data points. Have you worked out how much memory that takes? The server would blow up on the spot."

"Chu Ge."

Chen Zhuo gave a soft laugh into the phone.

"In real life, do you have a hundred thousand friends?"

"No. I don't even have ten."

Chu Ge answered honestly.

"No normal person does," Chen Zhuo said.

"So 99.99 percent of the entries in this matrix are 0. It's an extremely sparse matrix."

Chu Ge's fingers tightened around the pen.

"You don't need to store ten billion points in memory. You only need to store the coordinates of the ones."

Chen Zhuo went on.

"It's a simple coordinate mapping. Next question: you want friends of friends, the second-degree connections. How do you write that mathematically?"

Chu Ge's mind raced. The linear algebra he had learned as a freshman and mostly forgotten since suddenly split the fog in his head like a bolt of lightning.

"Matrix multiplication."

Chu Ge blurted it out.

"A times A. A squared."

"Right."

Chen Zhuo stood up, went to the coffee table, and poured himself a glass of warm water.

"In A squared, the nonzero entries are the second-degree connections. A cubed gives you the third-degree ones."

Chu Ge stared at the noodle lid, his pen drawing absent circles on it. His breathing had quickened.

"But matrix multiplication is way too much computation, especially at high powers. The CPU still can't take it."

Chu Ge had put his finger on the core problem.

"That's because you're being greedy. You want to compute everyone's whole network in one go."

Chen Zhuo took a sip of water to wet his throat.

"The server doesn't need to know who everyone knows. It only has to answer the request from whichever user is logged in right now. So you don't need to multiply a matrix by a matrix."

Chen Zhuo's voice went a little softer, but to Chu Ge it landed like a thunderclap.

"The logged-in user isn't a matrix. He's a vector."

Chen Zhuo gave him the final answer.

"A vector that's 1 in his own position and 0 everywhere else. Multiply that one-dimensional vector by the sparse matrix once and you get the vector of his direct friends. Multiply the result by the matrix again and you get his second-degree friends."

Chen Zhuo paused, then added:

"A vector times a sparse matrix is O(N). Even if he had connections ten thousand degrees deep, a computer doing that kind of one-dimensional array multiplication wouldn't need even a millisecond."

In the internet café, Chu Ge had chewed the lollipop down to nothing.

Only when he bit down on the stick and jarred his teeth did he snap out of it. He flung the stick onto the floor.

He stared at the oil-stained noodle lid in front of him.

On it were two lines of messy formulas.

For a full two weeks, that database deadlock had stumped the startup team in the capital. Several top students from Tsinghua's computer science department had written it off as an unsolvable hardware bottleneck.

This twelve-year-old boy had ground it to dust with a few of the most basic ideas in linear algebra, a dimensional strike if there ever was one.

"I get it."

Chu Ge's voice shook a little.

"Ditch the relational queries. Pull all the relationship tables out and maintain a sparse matrix in memory. Every query is vector multiplication done in memory, and once you have the result, you take the user IDs to the database to pull avatars and names."

"Right," Chen Zhuo said.

"There's one problem, though."

Chu Ge's programmer instincts had found the hole right away.

"A knows B, B knows C, and C knows A. In graph theory that's a cycle. If you keep multiplying the vector, won't it loop forever and burn through all the compute?"

"Chu Ge."

Chen Zhuo sighed into the phone, sounding a little helpless.

"That's an engineering problem, not a proof. Whenever an entry in the result comes out above 0, record the ID in a hash table. On the next multiplication, skip anything already recorded. Done."

Chen Zhuo shook his head slightly.

"You write code. Don't expect a math formula to tell you how many squares of toilet paper you need for a dump. Use a little programmer common sense, would you?"

Hearing the teasing on the line, Chu Ge suddenly broke into a grin.

"Fine. I owe you for this one, little bro. Consider it a debt."

Chu Ge folded the noodle lid twice and tucked it carefully into his inside pocket.

"When we're back at USTC after New Year, I'll buy you stir-fry at the canteen for a month. Gotta go. I need to get this low-level memory daemon written right now."

Before Chen Zhuo could say anything, the line went to a busy tone.

Chen Zhuo set the receiver down and shook his head, smiling a little.

He turned and went to the kitchen to get bowls and chopsticks for dinner.


In the capital, more than a thousand kilometers from Zeyang.

In a run-down apartment building near Zhongguancun.

The lights were off. Three or four monitors gave off a stark white glow. Now and then fireworks flared outside the window and lit up a floor littered with cigarette butts and half-eaten takeout boxes.

Wang Xing sat curled up in his computer chair in a padded jacket, his eyes bloodshot, staring at the back-end log on the screen.

They wanted to build a real-name campus social network in this lawless early era of the internet. The idea was excellent, and on the strength of a PowerPoint deck Wang Xing and his partners had already landed several hundred thousand yuan in angel investment.

But a technical bottleneck had them stuck.

Tomorrow was the third day of the New Year, and the investors wanted to see a demo that could handle five hundred users online at once.

Wang Xing hadn't slept in three days.

Whenever the concurrent load rose, the database queries behind the core friends-of-friends feature came down like an avalanche and dragged the whole system down with them.

The MSN icon in the bottom-right corner of the screen suddenly started flashing.

Wang Xing's bloodshot eyes flickered. He clicked it open.

It was Chu Ge, the freak of a hacker from USTC, way off in Huizhou, whom he had roped in as unpaid outside technical help.

"Lao Chu, don't bother."

Wang Xing typed it out, his fingers a little stiff.

"We tried caching, we tried indexing, nothing works. A relational database can't handle multi-level network queries like this. The hardware can't take it."

A few seconds later, Chu Ge sent over a zip file.

It was under 20KB.

Then a message from Chu Ge popped up.

"Delete all your old relationship-query code and run this C daemon in the background on your server."

Wang Xing paused.

"What is it?"

"An in-memory sparse matrix multiplication tool."

Chu Ge's reply was brief.

"Export your relationship table as plain text and feed it in. From then on, every friend query skips the database. Send the command straight to this process, it does the math in memory and hands you back an array of friend IDs."

Wang Xing read the message without really understanding it.

But he was out of options by now, so he decided to try it anyway and treat the dead horse as if it might still live[2].

He accepted the file, unzipped it, dragged the source code into the compiler, and skimmed it.

One look was enough to break him out in a cold sweat.

The code was extremely lean. It didn't include a single database connection library. It was all low-level memory pointer operations and a few one-dimensional array multiplication loops he couldn't quite follow.

There wasn't one SQL statement in it.

Wang Xing took a deep breath, put the compiled executable in the background of the test server, and loaded in tens of thousands of test relationship records.

The process started silently. It used less than fifty megabytes of memory.

"Run a stress test."

Wang Xing turned and called to Wang Huiwen next to him, who was nodding off where he sat.

Wang Huiwen groggily rubbed his eyes and typed a stress-test command.

"Simulating five hundred concurrent requests, third-degree friend queries."

Wang Huiwen hit Enter.

"Brother Xing, get ready to reboot the server. It'll probably crash in three seconds again…"

Before he could finish, his voice caught in his throat.

The stress tool's progress bar didn't freeze the way it had before. It filled almost too fast for the eye to follow.

The whole screen was green.

Wang Xing sat bolt upright, and his chair creaked under him.

He stared at the summary of the test results.

Requests completed: 500.

Failures: 0.

Average response time: 3 milliseconds.

Wang Xing thought he was seeing things. He turned to look at the server's resource monitor.

At the moment the stress test hit, CPU usage had blipped once to 8% and then dropped straight back to 1%.

The queries were finished before the server fans even had time to speed up.

The room was so quiet that all they could hear was the faint hum of the computer cases.

"Brother Xing…"

Wang Huiwen swallowed. The hand he was pointing at the screen was shaking.

"What happened? The database never even ran?"

"It never went through the database."

Wang Xing's voice had gone hoarse. He stared at the C code and finally understood the frightening math behind it.

It wasn't looking up data.

It was taking the entire network of user relationships and reducing it mathematically, directly in memory.

Wang Xing's fingers were going numb. He switched back to the MSN chat window and typed as fast as he could, not even stopping to fix his typos.

"Lao Chu! Who wrote the core logic?!"

Wang Xing sent three nudges in a row.

"This is pure fucking graph theory and higher linear algebra! It pulls the database's work out and hands it to the CPU as vector math in memory!"

Wang Xing's heart was pounding.

"Don't tell me you came up with this. Do you have an algorithms team from the Chinese Academy of Sciences behind you? Or did you get some search-engine bigshot in Silicon Valley to help?"

In an internet café in a small county town.

Chu Ge looked at the string of exclamation marks and the madly shaking chat window from Wang Xing, and a supremely smug grin spread across his tired face.

He picked up the box of lollipops beside him, a few dozen yuan's worth that he'd had a friend buy for him, pulled one out, and stuck it in his mouth.

Chu Ge flicked his ash into the noodle cup, rested both hands on the greasy keyboard, unhurriedly typed a line, and hit Enter.

"No team."

"Just a guy who lives in my dorm. He's home for winter break. He solved it offhand when I called him just now."

After sending that, Chu Ge paused, then twisted the knife.

"Oh, and he's twelve this year. His mom's probably calling him to come eat dumplings right about now."

On the other end, Wang Xing's MSN avatar went completely still.

A full five minutes passed.

Then Wang Xing sent a row of ellipses.

After that came a single message.

"Lao Chu, if the investors' money comes through tomorrow, I'll set aside five percent in sweat equity for you. Your roommate… could we bring him onto the team as a technical adviser? He can name his terms."

Chu Ge read it and gave a soft laugh.

"Forget it."

Chu Ge typed.

"We're a ragtag outfit, and you think someone at that level is going to be our technical adviser? Take these few lines of code as my New Year's present to you guys. Logging off. Going to sleep."

Chu Ge logged out of MSN without another word.

The air in the café was still foul. A few young guys from around town who had paid for the overnight rate were slumped asleep over their keyboards, snoring softly.

Chu Ge stood and gave a long stretch, and his joints cracked a few times.

He paid at the counter and pushed open the café's glass door.

A bitter wind hit him in the face and instantly blew away the cigarette smoke and the particular greasy-hair smell of internet cafés that clung to him.

Day was just breaking.

It was the morning of the third day of the New Year, and the streets were empty. The ground was covered in last night's red firecracker scraps, glaring against the leftover snow.

Chu Ge turned up the collar of his old army greatcoat and shoved his hands in his pockets.

He walked along the cold, empty street and breathed out a cloud of white.

It was the eve of an era of wild growth.

Some people stayed up all night at the card table. Some burned their eyes red in front of computers.

And the one who had actually shown them the way, what was he doing right now?

Chu Ge couldn't help smiling. He walked over the scraps of paper toward the guesthouse.


At the same time.

Zeyang, the Sunshine Staff Compound.

The TV was on in the Chen family's living room, showing a rerun of last night's Spring Festival Gala.

Feng Gong's "I've missed you all to death!"[3] echoed through the apartment.

The kitchen was full of steam.

"Xiao Zhuo! Stop wandering around the living room and go wash your hands!"

Liu Xiuying came out of the kitchen carrying two plates of freshly cooked dumplings, the steam blurring her face.

"Dumplings on the first day, noodles on the second, and on the third, pan-fried pockets to bring luck home.[4] Today it's pickled cabbage and pork dumplings. Come eat while they're hot, they'll stick together and go bad in a minute!"

Chen Jianguo sat down at the table with a few cloves of garlic and a bottle of aged vinegar.

"Coming, coming."

Chen Zhuo answered, went to the bathroom, and turned on the tap.

The matrices, the vectors, the high-dimensional mappings that had flashed through his head a little while ago vanished the moment Liu Xiuying called him for dumplings, gone like soap suds rinsed away under clear water.

The internet, six degrees of separation, none of it mattered.

On this third morning of the New Year, with snowflakes drifting and the smell of vinegar in the air, none of it was as real as the steaming plate of pickled cabbage dumplings on the table.

Chen Zhuo dried his hands, came to the table, and sat down.

"Mom, pour me some vinegar."

Chen Zhuo pushed the little porcelain dish over with the matter-of-course air peculiar to a twelve-year-old boy.

Liu Xiuying picked up the vinegar bottle and filled half his dish.

"Dumplings without garlic lose half their flavor. Peel your own."

Chen Jianguo tossed two cloves of garlic in front of Chen Zhuo.

Chen Zhuo picked them up and pinched them hard between thumb and forefinger. The skins split with a crisp crack.

Sunlight came in through the balcony glass and fell on Chen Zhuo's smooth, gentle face.

Everything felt so peaceful, and so natural.

[1] Diu lei (丢雷): a Mandarin rendering of a vulgar Cantonese curse, roughly 'fuck you', which spread through internet cafés along with Hong Kong films and online games.
[2] Treating a dead horse like a living one (死马当活马医): a common saying for trying anything at all in a hopeless situation, attributed to a Song-dynasty Chan Buddhist record.
[3] Feng Gong (冯巩): a crosstalk comedian who appeared at the CCTV Spring Festival Gala almost every year. He opened his acts with 我想死你们了, 'I've missed you all to death!', which became his famous catchphrase.
[4] A northern Chinese New Year folk saying that sets a food for each day of the holiday. The 合子 (hezi) are pan-fried pockets stuffed with chives and egg, and their name puns on 合, 'together, gathering in', so eating them is meant to keep good fortune at home.

This reader needs a modern browser to display fully. If you are using one, there may be network issues.