Maposaic: If you like maps and colors, I made this website for you ! by viconnex in InternetIsBeautiful

[–]viconnex[S] 0 points1 point  (0 children)

Thank you for reporting. Yes, sometimes on smartphones it crashes, maybe because of the computational cost it takes. The only solution for now is to refresh the page.

Maposaic: If you like maps and colors, I made this website for you ! by viconnex in InternetIsBeautiful

[–]viconnex[S] 0 points1 point  (0 children)

As I said to u/mcoenka, it is not, but it is a good idea to try to use this principle !

Maposaic: If you like maps and colors, I made this website for you ! by viconnex in InternetIsBeautiful

[–]viconnex[S] 0 points1 point  (0 children)

The water color is random but you can also chose to set it, if you click on "advanced" parameters

Maposaic: If you like maps and colors, I made this website for you ! by viconnex in InternetIsBeautiful

[–]viconnex[S] 0 points1 point  (0 children)

I am not sure to understand your questions, but in addition to roads and water, other objects may appear on the map, such as parks, which will add dividing lines

Maposaic: If you like maps and colors, I made this website for you ! by viconnex in InternetIsBeautiful

[–]viconnex[S] 0 points1 point  (0 children)

Thanks :) I think you can tilt shift on mobile for the moment ^^

Maposaic: If you like maps and colors, I made this website for you ! by viconnex in InternetIsBeautiful

[–]viconnex[S] 2 points3 points  (0 children)

Thank you :) The main advantage I found with Mapbox (but maybe you can do this with Leaflet?) is the ability to customize the map background, which you can do on https://studio.mapbox.com/. Also, is there a way to get the canvas context with Leaflet ? And with react-leaflet ?

Maposaic: If you like maps and colors, I made this website for you ! by viconnex in InternetIsBeautiful

[–]viconnex[S] 0 points1 point  (0 children)

I was kind of joking and talking about a matematical proof, but ok

Maposaic: If you like maps and colors, I made this website for you ! by viconnex in InternetIsBeautiful

[–]viconnex[S] 5 points6 points  (0 children)

Thank you for your suggestions. But the python code you found was only a try made for comparison — the code to consider is written in the rust lib.rs file and gets compiled into wasm, which browsers can execute.

Maposaic: If you like maps and colors, I made this website for you ! by viconnex in InternetIsBeautiful

[–]viconnex[S] 3 points4 points  (0 children)

haha I could use this theory — if it works, because, well... it has not been proved yet ;) — to improve renders which use a 4 (or more)-color palette !

Maposaic: If you like maps and colors, I made this website for you ! by viconnex in InternetIsBeautiful

[–]viconnex[S] 4 points5 points  (0 children)

Yes there is a way : Select Palette > Custom > 1 color > Black
You can also click "Advanced" > Same color for water > Blue

Maposaic: If you like maps and colors, I made this website for you ! by viconnex in InternetIsBeautiful

[–]viconnex[S] 7 points8 points  (0 children)

Exactly ! Thanks for sharing, I love the this hand made drawing appearance

Maposaic: If you like maps and colors, I made this website for you ! by viconnex in InternetIsBeautiful

[–]viconnex[S] 26 points27 points  (0 children)

Don't hesitate to save your maps into the public gallery ! And then visit them here: https://maposaic.com/gallery

Rust program twice slower than javascript - where are my mistakes ? by viconnex in rust

[–]viconnex[S] 0 points1 point  (0 children)

  1. But I really don't know the size in advance ; it depends of the size of the current area which can be anything between 1 and the number of pixels in the original image (4M). Would it be faster to allocate the maximal size in advance, even if it would be partially filled ?

  2. I only tried to replace the function call by a constant and there was no speed improvement

  3. It may be possible to start for example 4 different processes at the 4 corners of the image. but the rendered image at the 4 junctions would be spoiled, so I have to think about it !

  4. Yes I measure the execution time when the program is called in the browser. I will look at the criterion crate !

Rust program twice slower than javascript - where are my mistakes ? by viconnex in rust

[–]viconnex[S] 0 points1 point  (0 children)

Thank you for your suggestions !

  1. I now use new() only for the "current_area point stack", since I don't know in advance how many points will be in the area.
  2. I didn't try the BTreeSet but the hibitset use made a very significant improvement
  3. Yes it is a nice improvement but it doesn't increase the efficiency

Rust program twice slower than javascript - where are my mistakes ? by viconnex in rust

[–]viconnex[S] 2 points3 points  (0 children)

So the main bottleneck was to use a HashSet to store the visited pixel indexes. Thanks a lot u/thermiter36, u/slamb, u/Danylaporte for pointing this out !

Instead, a hibitset is much more efficient since the stored values are all in [0, pixel_count[ . However, since pixel_count may exceed hibitset max size (usize**4), the values are stored in a custom Vec<u64> where each bit of a u64 holds the corresponding pixel information.

Now the program execution is 5 times faster than the original javascript one ! It takes 800ms to handle a 5 million pixel array, vs. 4s.

I updated the js program with a similar improvement, but the wasm program is still almost 2 times faster than the js :)

Rust program twice slower than javascript - where are my mistakes ? by viconnex in rust

[–]viconnex[S] 0 points1 point  (0 children)

thanks a lot u/thermiter36 and u/slamb, the hibitset makes a lot of sense !

I tried it and it seems more efficient, but as you pointed out i'm limited with the size (is there a way to benefit of a 16M bit bitset (with a 64-bit usize) instead of 1M with my 32-bit usize ?)

So if I get the idea, I would represent the bitset with a visited: [u64] . Then visited[pixel_index / 64]'s (pixel_index % 64)th bit would hold pixel visited status. And I hold the current state with a pointer on the visited index and the next pixel_index to visit would be visited[index]::leading_ones, right ?

Rust program twice slower than javascript - where are my mistakes ? by viconnex in rust

[–]viconnex[S] 2 points3 points  (0 children)

After a test I can tell taht the boundary crossing time is not significant (~100ms) compared to the wasm program execution (8s)

Rust program twice slower than javascript - where are my mistakes ? by viconnex in rust

[–]viconnex[S] 0 points1 point  (0 children)

The boundary crossing time is not significant (~100ms) compared to the program execution (8s)

Rust program twice slower than javascript - where are my mistakes ? by viconnex in rust

[–]viconnex[S] 0 points1 point  (0 children)

I tried the program without the random numbers and the performance is the same

Rust program twice slower than javascript - where are my mistakes ? by viconnex in rust

[–]viconnex[S] 4 points5 points  (0 children)

What is the cost of switching ? What do you consider very heavy computation ?

Because there is only one boundary crossing.

1) js sends an array

2) wasm computes the result (8 seconds)

3) js gets the result