Comments (11)
I took a look at the different implementations and I think that it could be possible to adapt pympler's asizeof
implementation for Python >=3.2.
Here is my slightly modified implementation :
https://gist.github.com/Animenosekai/4e5a3a980e7ed2e542003a58a54ede96
from translate.
Maybe implement asynchronous checking and clearing the cache using ThreadPoolExecutor? This should speed up the caching process
from translate.
There is a small problem - it seems to me that it works a little slow, I still have no idea how to speed up
from translate.
I just tested the different implementations and yes our implementation is quite slow, pympler
's one is a bit faster but sys.getsizeof
is definitely the fastest (which is normal considering that there is no recursion).
from translate.
Or maybe we could check if the object is a native object, in which case we would check with sys.getsizeof
and we would use other implementations for more complex objects
from translate.
Maybe implement asynchronous checking and clearing the cache using ThreadPoolExecutor? This should speed up the caching process
Well I tried to implement it too in 58521f1 but seems to also be slow
I'll need to figure out why because it seems odd...
from translate.
So I tried to optimise the LRU cache, and it seems I have it. Some numbers:
raw dictionary implementation code:
import os
if __name__ == "__main__":
a = {}
for i in range(1_000):
print(i)
a[i] = os.urandom(200_000_0)
Also in the test, I changed the old LRU implementation to use os.urandom
instead of just putting numbers.
Just raw dictionary time:
python3 just_dict.py 0.03s user 8.59s system 99% cpu **8.643 total**
Old LRU cache implementation time:
python3 lru_old.py 48.94s user 8.59s system 86% cpu **1:06.65 total**
New LRU cache implementation time:
python3 lru.py 0.50s user 7.64s system 99% cpu **8.201 total**
time
shows that the new LRU implementation is like a zero-overhead. I think that's a good result. In the new implementation, instead of recomputing the cache size every time, it simply takes the object size into a separate class property, and uses these values to free the cache in the future.
New LRU implementation code:
https://gist.github.com/ZhymabekRoman/43ee515959de024416e29b8dd97e4d96
from translate.
Ohhh I understand how you did that. Really cool numbers!
Did you try on python <3.7 to see if it was working as well ?
from translate.
Did you try on python <3.7 to see if it was working as well ?
Hmm, no. I'll try to install debian stretch on my machine and test it there with Python 3.5.
from translate.
Yes, it works great! Some debugging shows that all the logic works as expected.
from translate.
I think this issue can be closed, since we have merged into next branch
from translate.
Related Issues (20)
- Consider adding the formality and glossary feature to DeepL HOT 5
- Bulk Translation support? HOT 2
- NoResult: No service has returned a valid result HOT 8
- Missing spaces between tags when using translate_html HOT 2
- Bing Translator throwing error code 205 HOT 5
- Not accurate source language autodetection HOT 14
- Language auto detecting is broken in MyMemory HOT 3
- example() not working HOT 1
- Next: 3.0 HOT 24
- Different Translation on Yandex HOT 11
- Result mismatch Google Translate HOT 5
- MicrosoftTranslate.text_to_speech is not working HOT 8
- Is the DeepL split text correct? HOT 3
- [SERVER]: cannot import name 'General' from 'nasse.config' HOT 1
- the lang tr is not supported by deepl error (even though it has) HOT 1
- How to set timeout for Translate requesting? HOT 8
- Links and hashtags seem to change after translation HOT 10
- ReversoTranslator BUG HOT 7
- No module named 'translatepy.utils' (on Windows) HOT 2
- Traditional Chinese HOT 1
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 translate.