Comments (2)
Here is a quick python script that finds repeated chunks and according to a efficiency-of-replacement metric decides whether to factorize them into a function or not. It reduces the size of the script to 5000 lines. Of course, there is a risk of breaking things since the script understands nothing about semantics. The compressed script works fine for me, but my intention was merely to show the amount of compression that can be achieved without losing functionality.
from collections import defaultdict
in_path = "/tmp/rclone"
out_path = "/tmp/rclone-small"
with open(in_path) as f:
script = f.read()
line_locs = defaultdict(list)
for loc, line in enumerate(script.splitlines(keepends=True)):
line_locs[line].append(loc)
chunks = []
prev_locs = []
for line, locs in line_locs.items():
if locs != [loc + 1 for loc in prev_locs]:
chunk_lines = []
chunks.append((chunk_lines, len(locs)))
chunk_lines.append(line)
prev_locs = locs
chunk_id = 0
for chunk_lines, chunk_reps in chunks:
chunk_size = len(chunk_lines)
ratio = (chunk_size + chunk_reps) / (chunk_size * chunk_reps)
if ratio < 0.5:
chunk_text = ''.join(chunk_lines)
chunk_fun = f"chunk_{chunk_id}"
script = script.replace(chunk_text, f" {chunk_fun}\n")
script += f"\n{chunk_fun}() {{\n{chunk_text}}}\n"
chunk_id += 1
with open(out_path, "w") as f:
f.write(script)
from rclone.
Closing this in favor of #7000.
This may be the solution: #7000 (comment)
from rclone.
Related Issues (20)
- s3 serve: Improve documentation: instructions unclear HOT 4
- rclone serve s3: invalid error response when using wrong password HOT 9
- Filtering and Unicode normalisation
- Upgrade to Go 1.22 to avoid scoping bugs with closures in for loops? HOT 4
- Improperly set "Range" header when retrying file download from Dropbox HOT 3
- Files on Windows vfs lost when file names contain CJK punctuations HOT 6
- s3 serve: incorrect format of Last-Modified header HOT 2
- Support blake3 / b3sum as hash HOT 5
- rclone FUSE mount does not reliably unmount when operations are in flight, leaving broken mount behind HOT 2
- mailru: change default pacer to reduce transactions per second HOT 9
- Google Drive: Rclone rewrites custom-set description on file rename in mounted drive HOT 1
- bisync: coloring in the logs not obeying --color or redirection HOT 1
- Provide `rclone/setup-rclone` action to setup rclone on the runner HOT 3
- Issue with rcolne in gdrive backup HOT 1
- Add support for scloud (SkyCloud) by API HOT 1
- rclone serve: support systemd socket activation HOT 1
- copy local files with --links, directories and links are created with wrong metadata(mod uid gid) HOT 1
- copy local files with --links ,directories and links are created with wrong metadata(mod uid gid)
- I encountered several errors while uploading to the PIKPAK cloud drive (investigated for over a week, identified the issues, hoping to assist in fixing). HOT 27
- cleanup: onedrive: delete version with newest modified date
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rclone.