Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance read/write speed even further #17

Open
Osiris-Team opened this issue Jan 10, 2022 · 0 comments
Open

Enhance read/write speed even further #17

Osiris-Team opened this issue Jan 10, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@Osiris-Team
Copy link
Owner

Osiris-Team commented Jan 10, 2022

image
To run this benchmark yourself simply clone this repo and run this test: https://github.com/Osiris-Team/Dream-Yaml/blob/d06e9d1a4985c985f9b3f589875d818938e2bb8d/src/test/java/YamlBenchmarks.java#L46

Research (read)

  • The postprocessing costs around 0,050ms - 0,100ms of extra time
  • The debugger costs around 0,100ms of extra time
  • Currently, we are using .readLine() and then go through that line again and check it char by char. Instead of going through it twice maybe there is a way of going through it only once.

Research (write)

The java.nio.channels package, specifically the FileChannel class provides methods for reading/writing stuff at specific positions of the file. This may drastically increase the writing speed for bigger files, since we would only write the changes instead of the whole file.
Possible logic for the above:

  1. Check if the file is empty. If it is simply parse and write all modules to it. Otherwise, continue:
  2. During read attach the keys and values start/end positions to the module. Now if the module was modified, aka the value/key was changed we write to those specific positions only.

There are however some negative aspects to this approach:

  • Extra memory needed to store each keys/values positions
  • The more time passes between read and write, the more likely it is that the file was changed in between and thus the positions are not accurate anymore which could lead to breaking the yaml file
  • We would need to recalculate the position of all keys/values with each modification I think
  • The above would not work for Input-/Output- Streams
  • We would also need to store the old/unmodified value/key to recalculate the location
@Osiris-Team Osiris-Team added the enhancement New feature or request label Jan 10, 2022
@Osiris-Team Osiris-Team changed the title Enhance DreamYamls read/write speed even further Enhance read/write speed even further Jan 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant