DevOps

More than half of GitHub is duplicate code, researchers find

Boffins beware: random samples are therefore useless for research

By Richard Chirgwin

30 SHARE

Given that code sharing is a big part of the GitHub mission, it should come at no surprise that the platform stores a lot of duplicated code: 70 per cent, a study has found.

An international team of eight researchers didn't set out to measure GitHub duplication. Their original aim was to try and define the “granularity” of copying – that is, how much files changed between different clones – but along the way, they turned up a “staggering rate of file-level duplication” that made them change direction.

Presented at this year's OOPSLA (part of the late-October Association of Computing Machinery) SPLASH conference in Vancouver, the University of California at Irvine-led research found that out of 428 million files on GitHub, only 85 million are unique.

Before readers say “so what?”, the reason for this study was to improve other researchers' work. Anybody studying software using GitHub probably seeks random samples, and the authors of this study argued duplication needs to be taken into account.

As open source watcher Adrian Colyer blogged, “simple random selection is likely to lead to samples including high duplication, which may bias the results of research”, so the paper's resulting public index of code duplication, which they've dubbed “DéjàVu”, helps “understand the similarity relations in samples of projects, or to curate sample to reduce duplicates”.

For example, the study said, if a researcher is studying how many C and C++ programs use assertions, duplication clearly skews their output; similarly, a software quality study needs to take duplication into account.

X = files, Y = commits, Color = dupes. Source: DéjàVu: A Map of Code Duplicates on GitHub, Lopes et al at ACM

DéjàVu maps file clones in Java, C++, JavaScript and Python.

The researchers assessed code duplication using a variety of hash techniques. Identical code was easy, since they produced identical hashes, but it was also necessary to take into account software with small changes (spaces or tabs), or even larger changes.

To draw these other duplicates into their sample, the researchers applied a “token hash” that captured minor changes in spaces, comments, and ordering; and a package called

SourcererCC

to capture clones with edits too large for the token hash.

JavaScript was the most cloned environment of all: a mere six per cent of files spawned the other 94 per cent of JavaScript files on GitHub. Of the C++ ecosystem, 73 per cent of files were duplicates; 71 per cent of Python programs were dupes.

Java developers are the most individualistic of the four environments researched, “but even for Java, 40% of the files are duplicates”.

The other thing that probably won't surprise readers is that duplication is primarily dependency-driven. JavaScript provided a good example: people creating a project would commit NPM libraries into their new repositories as if they were part of the application code.

As Colyer wryly noted: “If ever you have felt like you are downloading the universe when running npm install, here’s the data to prove it: including nested dependencies (nesting up to 47 levels deep was discovered, with median five) the number of unique included projects has median 63, and maximum 1261.”

Similarly, nearly all JavaScript programmers suck JQuery into their projects.

There's also programmers' habits as Git users: “there is a lot more duplication of code that happens in GitHub that does not go through the fork mechanism, and instead, goes in via copy and paste of files and even entire libraries”, the study noted. ®

Sign up to our NewsletterGet IT in your inbox daily

30 Comments

More from The Register

Intel outside: Apple 'prepping' non-Chipzilla Macs by 2020 (stop us if you're having deja vu)

Plus: Samsung overtakes in semiconductor revenues

123 Reg suffers deja vu: Websites restored from August 2017 backups amid storage meltdown

Daily backups? We've heard of them

Windows Mixed Reality: Windows Mobile deja vu?

Unloved by customers, and less and less loved by retailers

FireEye hacked off at claim it hacked Chinese military's hackers

Allegation in book mistook RDP recording for real world action, company asserts

When should I run backup, robot overlord? Autonomous Hadoop and NoSQL backup is now a thing

Imanis Data bets data management farm on backupbot

Subscription disappointments keep FireEye in the red

At least the company found and cuffed an internal hacker

PasteBin data dump: Hackers claim files are from Mandiant FireEye 'breach'

Security analysts: None of our systems were pwned

FireEye close to settling lawsuit

Nice chunk of change

FireEye pulls Equifax boasts as it tries to handle hack fallout

Now credit freezes may not even be secure

MongoDB shoots for $220m in IPO, values NoSQL biz at $1.2bn

Trading due to begin on NASDAQ today