Comments (11)
In an early version, qstr's were exactly their pointer. The main reason to make them an index into a table was to make them smaller. In the byte code, constants (like qstr's) are encoded with a variable width encoding (like UTF-8). Thus, smaller numbers lead to smaller byte code. Pointers are not small, they have high-bits set.
from micropython.
Another place where I see that pointers won't fit is parse.h/mp_parse_node_t, which uses 4 tag bits.
But well, what we can do about this is to use pointers when possible, and when not, use handles. For example, with qstr pools, handle lookup is no longer O(1). Yeah, with exponential pool size growth it's O(log N), but exponential growth is greedy on memory, and why look up at all, if we can use pointer right away?
from micropython.
But well, what we can do about this is to use pointers when possible, and when not, use handles.
I was just pondering this exact point. I think it would be better to have qstrs as direct pointers to their data (their hash, len and bytes). But how to compress them in the byte code? CPython uses a table of strings, and byte codes index that table.
from micropython.
Well, first of all, static qstr table should be much bigger than it is now - include builtin functions/objects/their methods, etc. For other strings, compiler will intern them unconditionally so far, so you'll get qstr index, and can store it varlen in bytecode. On interpreting bytecode, just applies qstr_str() immediately and store ptr in all structures. Do I miss some additional issues?
from micropython.
On interpreting bytecode, just applies qstr_str() immediately and store ptr in all structures.
That's going to have a big performance penalty. Eg LOAD_ATTR, you would need to convert qstr_idx to qstr_ptr, requiring a very complex operation to search the qstr pools. Then you do a dictionary lookup to find the attribute you wanted (insignificant compared with qstr_str call). This would happen each time the byte code was executed.
from micropython.
requiring a very complex operation to search the qstr pools
Then you do a dictionary lookup to find the attribute you wanted (insignificant compared with qstr_str call)
How is it very complex? And how dictionary lookup is insignificant? Exponential pool look up will have worst-case complexity O(log N) (N - total number of items). For dictionary, worst case is O(N). Realistically, 5-10 backtracks thru pools will be enough (well, it should improve once we make not all string intern), once pool is found, it's O(1). Dictionary of some class can easily have 20 attributes ;-), and due to algorithm used, even on average you'll need to loop thru 1/2 of items.
But all in all, if it's clear that some operation requires speed, we should use ptr (even in bytecode I mean). (And as it can't be that clearly really, having configurable even better ;-) ).
from micropython.
Ok, I still fill slight intuitive dissatisfaction with this extra indirection design, but it's pretty deep into interpreter now, and any resolution should take #222 needs into account (and that either means sticking with handles, or have different format for persistable and loaded bytecode, which is bloat).
So, closing for now.
from micropython.
I don't mind leaving this open, since it reminds me to think deeply about the problem :)
from micropython.
Ok, let's keep open, but #386 would be still more important to resolve sooner.
from micropython.
I don't see a reason to keep this open anymore. Having small bytecode size (and hence compressed/indexed qstrs) is much more important than optimising for speed. And there are places now in the code which assume only 16-bit of storage for qstrs (especially when persistent bytecode is enabled).
from micropython.
Ack. I try to to old ticket cleanup myself from time to time, and wanted to close these my "green naive" tickets too, but wanted to re-read them first to see what direction we went since then, but that doesn't happen for months, so just closing them sounds good.
from micropython.
Related Issues (20)
- esp32.wake_on_ext0 not workingon esp32s2 HOT 1
- ISR latency affected by BLE, unable to interface with 2kHz sample rate ADC. HOT 2
- Include a WASM interpreter as part of micropython or its standard library? HOT 3
- Renesas-RA: Pin-IRQ does not behave as expected. HOT 5
- MQTTS fail on ESP32-S3 but works in ESP32
- Cannot instantiate FrameBuffer from a bytes object HOT 9
- Build errors when building RPI_PICO for debug HOT 1
- mpremote cannot cat with recent MP on pyboard HOT 4
- asyncio module seems missing in self built firmware for ESP8266 board HOT 6
- nimble compile errors HOT 2
- ESP32-S3 Linking errors HOT 5
- esp32 wroom - guru meditation - socket accept (?) HOT 1
- esp32 - mDNS not working HOT 1
- rp2 - mDNS not working HOT 1
- rp2: Nonsense REPL input on Linux due to tty serial input echo race HOT 16
- docs: WLAN module, undocumented methods
- mpremote mount chdir() in mount fails after second call HOT 5
- STM32F407+MII+DP83848 not working properly HOT 20
- ESP32 SPIRAM IRAM overflow
- ESP32 Outputting Garbage in REPL 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 micropython.