Comments (6)
Regarding size, claims on the README page are based on checking assembly dumps.
Today I can tell what worked for me in complete projects for reducing code size:
- don't use global variables (LDS/STS instructions are 4 bytes and may be used in many locations where a global variable isaccessed)
- avoid virtual: each class with virtual methods has a vtable stored in flash (and copied to SRAM I believe), which seems to be 4 bytes + 2 bytes per virtual method
- avoid vectors if you can (each vector will generate several dozen instruction to push and pop registers): of couse, this is easy said but performance generally requires interrupt vectors, so you have to make your choices.
- use templates for all IO, which enforce CBI/SBI use to access one pin
- use smallest, unsigned, types as possible
- force inline in some instances
- avoid switch and use if else constructs instead
- concentrate all pins on one port and make setup in one time, rather than pin per pin.
I am still yet to find other tricks for further size reduction.
from fast-arduino-lib.
Note that my purpose is not to make some comparison benchmarks to see which library is the best.
The main reason I quit Cosa was that some projects would not fit in an ATtiny84A and taking a look at the assembly made me think there were better ways to optimize.
from fast-arduino-lib.
@jfpoilpret I can only agree with your notes on optimizations. As you already know Cosa has grown considerably since support for ATtiny was introduced and there are many changes that do not favor for these devices. Actually this puts footprint reduce back on the agenda :)
As you will notice some of the design decisions you take in the beginning of the project will affect scaling. I did several version with templates in the beginning but abandoned them.
Also I should mention that the Soft::UART design has very limited optimization put into it. It has not even been update for the new GPIO pin support.
The interesting thing is to see further development for other IO devices and making a clear interface for device drivers especially support for multiple devices on SPI (which is an interesting challenge :).
Last but not least many of the constructs in Cosa actually need link time optimization to be reduced. If you have been using the Arduino IDE prior to 1.6.10 there was no support for that and the foot print was larger in general compared to building with Cosa command line (makefile). This might explain why I have not observed the footprint increase for ATtiny.
Keep up the good work!
from fast-arduino-lib.
PS: I guess you will be adding some benchmarks?
from fast-arduino-lib.
Actually, size benchmarks are already present (but outdated since I have started refactoring using "traits") in examples-data.xlsx file
I did not consider (so far) performing speed benchmarks but I might add this early next year (I still have too much stuff, more urgent, for 2016).
from fast-arduino-lib.
@jfpoilpret After nearly a year I recently got some time to circle back to "GPIO". I started off considering some of your observations of the Cosa design style and stepped back to look at the boarder picture of refactoring towards supporting both AVR and SAM architectures.
This resulted in an Arduino library for GPIO, https://github.com/mikaelpatel/Arduino-GPIO, with 1) no SRAM usage, 2) single instruction operations, 3) very easy to use, 4) possible to handle multiple architectures within the same source code baseline. The spin-offs are a few new libraries for OWI, TWI and SPI and a bunch of drivers.
If you have the time please take a look. The benchmarks are impressive; up to 100X compared to Arduino Mega.
from fast-arduino-lib.
Related Issues (20)
- Simplify some FastArduino API/implementation HOT 2
- Improve API documentation by fixing doxygen warnings HOT 1
- Add support for Grove 125KHz RFID reader HOT 1
- Improve software UART for slow rates
- Add support for RC522 (RFID chip) HOT 1
- Add support for Nokia 5110 LCD display HOT 1
- Add support for ILI9340 color display
- The Functor in I2C implementation appears to not working as expected HOT 4
- Allow SPI to work without a CS pin HOT 2
- Add support for Arduino LCD HOT 1
- Add support for Adafruit Bluefruit LE SPI Friend
- Add FastDigialPin as type HOT 3
- Improve APIDOC to properly generate sub-namespace docs HOT 1
- Compatibility with avr libraries HOT 3
- Renaming library... HOT 2
- Allow real Timer suspend/resume and set timer value HOT 3
- Add support for ATmega644 and 1284 HOT 3
- Queue buffer size waste improvement needed (was: Queue full bug) HOT 6
- Remove included streams.h to avoid conflicts with empty_streams.h HOT 1
- Review (replace?) virtual methods in ostreambuf and futures HOT 2
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 fast-arduino-lib.